Hey guys :) I''m wondering how I would go about getting a :dependent behavior on a habtm relation... It seems logical enough not to have :dependent on habtms, because habtm usually has to do with two different models that are "valid in themselves, independently of each other", or how to put it... But, in this particular case, the models are actually dependent. What I have are users, businesses, and addresses. A user can have a number of addresses, and they will belong to this user only. Likewise, a business can have a number of addresses, which again belong only to the business. So, I really do need the M2M-table but it''s not really a "has and belongs to many" relationship, it''s actually more like a "user has many addresses, but so do business, and thus I can''t have a foreign key to user in an address". Finally, when I delete a user, I''d like for the addresses to be deleted as well. But I don''t have a :dependent option... What would you do? Thanks in advance, Daniel :) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 5, 2007, at 5:10 PM, Daniel Smedegaard Buus wrote:> I''m wondering how I would go about getting a :dependent behavior on a > habtm relation... It seems logical enough not to have :dependent on > habtms, because habtm usually has to do with two different models that > are "valid in themselves, independently of each other", or how to put > it... > > But, in this particular case, the models are actually dependent. What > I have are users, businesses, and addresses. A user can have a number > of addresses, and they will belong to this user only. Likewise, a > business can have a number of addresses, which again belong only to > the business. > > So, I really do need the M2M-table but it''s not really a "has and > belongs to many" relationship, it''s actually more like a "user has > many addresses, but so do business, and thus I can''t have a foreign > key to user in an address". > > Finally, when I delete a user, I''d like for the addresses to be > deleted as well. But I don''t have a :dependent option...This is the canonical example for polymorphic associations :-). -- fxn --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 5, 5:43 pm, Xavier Noria <f...-xlncskNFVEJBDgjK7y7TUQ@public.gmane.org> wrote:> > This is the canonical example for polymorphic associations :-). >Indeed! :D Thanks :)> -- fxn--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---