@todo think of a better a way how to call it automatically after BuildExpr UpdateQuery implements `search.FieldResolver` interface. Conditionally updates the provided search query based on the resolved fields (eg. dynamically joining relations).
(query *dbx.SelectQuery)
| 133 | // Conditionally updates the provided search query based on the |
| 134 | // resolved fields (eg. dynamically joining relations). |
| 135 | func (r *RecordFieldResolver) UpdateQuery(query *dbx.SelectQuery) error { |
| 136 | if len(r.joins) > 0 { |
| 137 | r.updateQueryWithDeduplicateConstraint(query) |
| 138 | |
| 139 | for _, join := range r.joins { |
| 140 | query.LeftJoin( |
| 141 | (join.TableName + " " + join.TableAlias), |
| 142 | join.On, |
| 143 | ) |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | // note: for now the joins are not applied for multi-match conditions to avoid excessive checks |
| 148 | if len(r.listRuleJoins) > 0 { |
| 149 | for _, join := range r.listRuleJoins { |
| 150 | err := r.updateQueryWithCollectionListRule(join.collection, join.tableAlias, query) |
| 151 | if err != nil { |
| 152 | return err |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | return nil |
| 158 | } |
| 159 | |
| 160 | func (r *RecordFieldResolver) updateQueryWithCollectionListRule(c *Collection, tableAlias string, query *dbx.SelectQuery) error { |
| 161 | if r.allowHiddenFields || c == nil || c.ListRule == nil || *c.ListRule == "" { |