I have the following models:
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
belongs_to :account
end
class Account < ActiveRecord::Base
has_many :users
has_many :spies
has_many :public_listings, through: :spies
end
class Competitor < ActiveRecord::Base
belongs_to :integration_platform
belongs_to :account
has_many :spies
end
class Spy < ActiveRecord::Base
belongs_to :account
belongs_to :competitor
has_many :spy_relationships
has_many :public_listings, through: :spy_relationships
end
class SpyRelationship < ActiveRecord::Base
belongs_to :spy
belongs_to :public_listing
end
class PublicListing < ActiveRecord::Base
has_many :spy_relationships
end
I am having trouble doing two things:
1) In a controller, how can I look up all of the PublicListings associated with any given user (via their account > spies > spy relationships)?
2) As I pull the public_listings, is there any way to determine which competitor they are associated with and assign that to an attribute of the PublicListing (via spy_relationship > spy > competitor)?
Thanks