开发者

Creating a Scope that joins user_id with the User Table (user.id) --- Rails 3

I'm using Rails 3 with devise.

I have a table books which has a column for user_id, w开发者_运维百科hich is related to the Users table (user.rb)

I'm trying to create a Scope that shows all the books with the user's email address (Books joined to Users)

class Note < ActiveRecord::Base
 scope :personal, proc {|user| where(:user_id => user.id) }
end

Can you help me understand why this is erroring with: "Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id"

thanks


You need define a belongs_to assocation.

class Note < ActiveRecord::Base
 belongs_to :personal, :class_name => 'User', :foreign_key => 'user_id'
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜