I want to be able to query user.items and item.owner, in code:
class Item < ActiveRecord::Base
has_one :owner, :class_name => "User"
end
class User < ActiveRecord::Base
# What goes here?
has_many :items
end
I added to the Item model a column owner_id, how do I construct the User model so it uses owner_id instead of user_id when I call user.items?
The item table need to contain a user_id column. If you want to set this key by hand then you should use:
Have a look at:
http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html
and
Defining foreign key relationships for Rails' models