Commit 103de1a
authored
Fix relationship record retrieval
If a custom filter condition is supplied to any of the With{Type} methods the foreign key condition is not actually added to the query. While this doesn't break the retrieval it does pull a lot of unnecessary data into memory.
For a type A that has a 1:N relationship to type B the queries look like these:
```sql
SELECT __a.id, __a.c_id FROM a __a LIMIT 1 OFFSET 0;
SELECT __b_Other.id, __b_Other.attribute, __b_Other.a_id FROM b __b_Other WHERE __b_Other.attribute = $1; -- current
SELECT __b_Other.id, __b_Other.attribute, __b_Other.a_id FROM b __b_Other WHERE (__b_Other.attribute = $1 AND __b_Other.a_id IN ($2)); --fixed
```
```golang
type A struct {
kallax.Model
ID int64 `pk:"autoincr"`
Other []B
}
type B struct {
kallax.Model
ID int64 `pk:"autoincr"`
Attribute int64
}
```1 parent e1a0ba6 commit 103de1a
1 file changed
+1
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
178 | | - | |
| 178 | + | |
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
| |||
0 commit comments