Hey Wes,

If you use foreign key constraints, then all orphaned records would have
the foreign key set to null. If not, you'd have to do an outer join to
determine what is orphaned. Given this divergence, IMO this is best left to
the author.

-Ben


On Mon, Apr 8, 2013 at 2:57 PM, Wes Gamble <[email protected]> wrote:

> For purposes of maintenance and data cleanup, sometimes it is helpful to
> determine if you have orphaned records in your AR backing store.
>
> Assuming that an AR::Base descendant has one or more belongs_to
> associations, I propose the addition of built-in
> "<association_name>_orphaned" scopes that would return the set of records
> where the belongs_to association record doesn't exist. Using association
> introspection, this would be fairly straightforward.
>
> However, I'm not certain about the idea of having a "built-in" scope, as
> I'm not sure if any even exist at this point. Is this better implemented in
> a standalone gem that would then add these scopes?
>
> Many thanks,
> Wes
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Core" 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].
> Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" 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].
Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to