On 8 August 2015 at 14:45, Kévin Lesénéchal <
kevin.le...@gmail.com> 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