AnApprentice
AnApprentice

Reputation: 111070

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 in there, is there some way to tell Rails that the user is creator_id ?

Thanks

Upvotes: 0

Views: 223

Answers (1)

John
John

Reputation: 9456

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

Upvotes: 3

Related Questions