On 8 August 2015 at 14:45, Kévin Lesénéchal <[email protected]> wrote: > Hey everyone, > > I've got two models: Admin and CallCenter. An Admin may belong to a > CallCenter (the field is nullable). To keep history, Admins and CallCenters > have a deleted field with, for both of them: > > default_scope { where(deleted: false) } > > Now, I want to implement Admin.all_detailed which will retrieve all > non-deleted admins with their call center (LEFT JOIN). Simply doing a > eager_load will make a join with the default_scope condition, thus, > non-deleted admins which belong to a deleted call center will be shown not > having one.
I suggest that the problem may actually lie with your db design. If I understand your question correctly you allow a non-deleted admin to belong to a call center that that has been deleted, which seems odd. Perhaps consider what is the status of a "deleted" call center that still has associated admins. Is this in fact truly deleted or should it not be considered deleted until it has no more admins? As a side note I now avoid default_scope whenever practical, the use of it regularly turns up problems similar to yours. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLu0yE1inm%2B7KGDpa2_VAgESpPKyh0tRg5VV4V__QF2q4g%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.

