Ruby on Rails Tuesday, November 30, 2010

On 30 November 2010 10:14, Yan Bernatsky <lists@ruby-forum.com> wrote:
> I have 3 models
> Skill, User, UserSkill
>
> User has_many skills :through => :user_skills
> User has_many :user_skills
>
> UserSkill.new # => { :id => nil, :user_id => nil, :skill_id => nil }
> us = UserSkill.create(:user_id => 1, :skill_id => 1) # => { :id => nil,
> :user_id => 1, :skill_id => 1 }
>
> Why id is nil?
> In the database record was created and id is not null...

The id is not allocated until the record is saved to the database.

Colin

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

No comments:

Post a Comment