Pesho Petrov wrote:
> hi all,
> 
> I have a table "memberships". It has a field user_id, which I want to
> use as a foreign key to the "users" table.
> 

In that case you should have :
    "has_many :memberships" in the User model class
and "belongs_to :user" in the Membership model class

If you want all related memberships destroyed when deleting a user, you 
must write this in the User class:
 "has_many :memberships, :dependent=>:destroy"

(See 
http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#M001789
 
for more info about :destroy option)
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to