Skip to content

Instantly share code, notes, and snippets.

@elentras
Created March 30, 2011 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elentras/894463 to your computer and use it in GitHub Desktop.
Save elentras/894463 to your computer and use it in GitHub Desktop.
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