On Thursday, July 12, 2012 6:42:42 AM UTC-7, Jamie Hodge wrote:
>
> Hi Jeremy,
>
> I suspect this is SQL 101, but I will ask anyway.
>
> I have the following models:
>
> Item
>   many_to_many :authors
>   one_to_one :asset
>
> Author
>   many_to_many :items
>   one_to_many :approvals
>
> Asset
>   many_to_one :item
>   one_to_many :approvals
>
> Approval
>   many_to_one :asset
>   many_to_one :author
>
> An approval should be added/removed to any author added/removed to an item 
> that has an asset. I am currently using after_add and after_remove hooks to 
> achieve this. How can I push this relationship down to the database level, 
> such that approvals are destroyed through cascade when authors are removed 
> from items? I believe the ActiveRecord approach would be to use has many 
> through. What do you recommend?
>
>
If you want to "push this down to the database level", you'll probably have 
to write a database trigger.  I'm not sure what ActiveRecord's has_many 
:through has to do with that, though.

>From what you've described, using after_add/after_remove seems fine, though 
using a database trigger may be better.

Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sequel-talk/-/UWKDRuSaHqIJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to