开发者

Rails - Generating a new Model

If I have two models like this:

PhotoAlbums (id, creator_id)

Photos (photo_album_id, name)

In the PhotoAlbums controller, when I put a Belongs_to user开发者_StackOverflow in there, is there some way to tell Rails that the user is creator_id ?

Thanks


Try belongs_to :user, :foreign_key => :creator_id

Just to be clear, you would call the belongs_to association method in your PhotoAlbums model, not the controller (i.e., models/photo_album.rb).

Take a look at the following API Documentation for more information on how to override the conventions that Rails uses for the belongs_to method. http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#method-i-belongs_to

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜