I have three models: RequestForQuote
, CounterQuote < RequestForQuote [inherit RequestForQuote]
and Proposition
.
A request_for_quote
has_many propositions
, and a proposition
can act as a tree with a counter_quote
.
I already have :
class RequestForQuote < ActiveRecord::Base
has_many :propositions, :dependent => :destroy
end
class CounterQuote < RequestForQuote
end
class Proposition < ActiveRecord::Base
belongs_to :request_for_quote
end
How can I model it ? Thanks.
If a Proposition can have only one CounterQuote, you can use this:
class RequestForQuote < ActiveRecord::Base
has_many :propositions, :dependent => :destroy
end
class CounterQuote < RequestForQuote
belongs_to :proposition
end
class Proposition < ActiveRecord::Base
belongs_to :request_for_quote
has_one :counter_quote
end
CounterQuote would have attributes proposition
and propositions
, which is not very clear, consider renaming of these.
If CounterQuote can have many propositions, I agree with Tass, you can merge CounterQuote and RequestForQuote. If you need a tree structure (with parent and children), look at existing gems like awesome_nested_set .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.