multiple associations between 2 models - Rails 3 -


i trying have 1 many , many many relationship between 2 models in cms application. situation being following.

  1. owner(user) has many contents, content has owner
  2. user has many contents, content has many users

my models follows:

class user < activerecord::base   has_many :mycontent, :class_name => "content", :as => "owner"   has_many :content_users   has_many :contents, :through => :content_users end  class content < activerecord::base   has_attached_file :attachment    belongs_to :owner, :class_name => "user"   has_many :content_users   has_many :users, :through => :content_users end 

for reason not working correctly me. please help. thank you.

it helped if explained problem, think, it's :as => "owner" part. stated in [this][1] guide:as` used polymorphic associations (with polymorphic associations, model can belong more 1 other model, on single association - comments model can associated news , articles).

so instead of :as should use :foreign_key => 'owner_id'


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -