Topic: Relationships.

Hi guys,

if I have a user table(belongs_to :team) and a team table(with has_many :users) that has a user_id column in it. if I delete the user will the delete also take place in the team table? or is there a more specific way of doing it.

--

Re: Relationships.

If a team has_many :users, then it shouldn't have a user_id column, as that would mean it can only have one user (belongs_to :user). Perhaps you want a team_id column in the users table instead?

Railscasts - Free Ruby on Rails Screencasts

Re: Relationships.

bugger it was an example that i've got backwards.

what I'm after is that if I delete a user. will it delete any user_id's in other tables automatically if I havn't used forignkeys in the db. but have somehow managed to get the relationships right?

--

Re: Relationships.

Yep. Check out the :dependent option for the has_one and has_many methods. If you need an example, let me know.

Railscasts - Free Ruby on Rails Screencasts