We have models A, B, C such that
A has_many B :through C
Given a in A, b in B, is there a direct way to ask for the cs in C that belong to both without using explicit IDs in AR calls? I got
a.cs & b.cs
but involves two queries.
-- fxn
We have models A, B, C such that
A has_many B :through C
Given a in A, b in B, is there a direct way to ask for the cs in C that belong to both without using explicit IDs in AR calls? I got
a.cs & b.cs
but involves two queries.
-- fxn
Because AR is designed in such a way that using an _id column explicitely for simple things triggers a warning in my head, since it usually means I am not using the abstractions correctly.
We can here use #detect on a.cs, or a dynamic finder a.cs.find_by_b_id(b.id), but looks non-idiomatic, so I asked whether I am missing something. Perhaps in this particular case there is no prepackaged way to do this, in which case I'll remove the auto-warning :-).
-- fxn