Skip to content

Instantly share code, notes, and snippets.

@elentras
Created Mar 30, 2011
Embed
What would you like to do?
class Issue < ActiveRecord::Base
has_many :line_items, :as => :itemable
has_many :orders, :through => :line_items
end
class LineItem < ActiveRecord::Base
belongs_to :order
belongs_to :itemable, :polymorphic => true
end
class Offer < ActiveRecord::Base
has_many :line_items, :as => :itemable
has_many :orders, :through => :line_items
end
class Order < ActiveRecord::Base
belongs_to :user
has_many :line_items
has_many :issues, :through => :line_items, :source => :itemable, :source_type => 'Issue'
has_many :offers, :through => :line_items, :source => :itemable, :source_type => 'Offer'
end
class User < ActiveRecord::Base
belongs_to :user_session
has_many :orders, :conditions => "status = 'Completed'"
## Source de mes soucis :
has_many :issues, :through => :orders, :source => :issue, :conditions => "status = 'Completed'"
has_many :offers, :through => :orders, :source => :offer, :conditions => "status = 'Completed'"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment