I'm a little stuck on how relationships are defined between models in different namespaces. I have created this example to illustrate my problem and have added comments with my requirements.
class User < ActiveRecord::Base
has_one :account # meaning Account
end
class Account < ActiveRecord::Base
belongs_to :user # meaning User
has_many :campaigns # meaning campaigns
has_one :account # meaning SomeCollection::Account
end
class Campaign < ActiveRecord::Base
belongs_to :account # meaning Account
end
class SomeCollection::Account < ActiveRecord::Base
belongs_to :account # meaning Account
has_many :campaigns # meaning SomeCollection::Campaign
end
class SomeCollection::Campaign < ActiveRecord::Base
belongs_to :account # meaning SomeCollection::Account
end
The one I am most confused about is the relationship between Account
and SomeCollection::Account
. I would expect to access an instance of this as such -
account.some_collection_account
# => <SomeCollection::Account ...>
Aucun commentaire:
Enregistrer un commentaire