I have created models in rails using
rails g model User uid:integer name:string
and
rails g model Post message:string user:references
The above lines generated models like following
class User < ActiveRecord::Base
attr_accessible :name, :uid
end
and
class Post < ActiveRecord::Base
belongs_to :user
attr_accessible :message
end
Now do i need to explicitly add a has_many :posts in the User model ?
also how can i make user_id in Post model NOT NULL ?
Thanks.
Yes if you want to find posts of user User.firs.posts
Add migration