has_and_belongs_to_many or has_many for user/group relationship?
问题 I'm working on a Rails 3.1 app that has the following models: User: class User < ActiveRecord::Base has_and_belongs_to_many :groups has_many :ownerships, :class_name => 'Group' end Group: class Group < ActiveRecord::Base has_and_belongs_to_many :users has_one :owner, :class_name => 'User' end There's a join table between them, and the groups table also has a "user_id" column. I would expect to be able to write this in my groups_controller.rb @group = Group.find(params[:id]) foo = @group.owner