On Nov 8, 9:12 am, Shandy Nantz
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> I have two tables: airlinememberships and loyaltycars. The loyaltycars
> table just keeps track of what car memberships people want to asscoiate
> with an airlinemembership program. So that means that loyaltycars
> belongs_to => :airlinemmebership which means that I have a
> airlinemembership_id column in my loyatlycars table. Then in my
> ailrinemebership table I have has_many :loyaltycars, :dependent =>
> :destroy.
>
> So my question is when I delete an airlinemebership from the table does
> that also delete the asscoaition from the loyaltycars table based on the
> fact that I have a field in that table holding the airlinemembership id
> by way of that :destroy statement?
Yes. But you must use destroy to delete the airlinemembership, not
delete.
Be careful, delete just is lower level method to delete records as it
skips any dependancy checking you may have. But it is faster if you
need to delete a lot of records quickly and you don''t care about
integrity checks.
> Also when looking at the documention for the models there is a :destroy
> and a :destroy_all. What is the difference between the two.
Destroy only worths with ids, and you can pass multiple id numbers to
destroy. Destroy_all can work with any condition you want, like
airlinemembership.destroy( "active = false").
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---