Rails 3.2: (activerecord) ¿Cómo modelo esto?

enter image description here

Tengo tres modelos: RequestForQuote, CounterQuote < RequestForQuote [inherit RequestForQuote] y la Proposition.

A request_for_quote tiene muchas propositions, Y un 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.

preguntado el 02 de febrero de 12 a las 10:02

Not sure if I understand but, class Proposition; has_one :counter_quote end; will that not help? -

I'd probably merge CounterQuote y la RequestForQuote a Quote. For recursive querying, you'll have to use recursive views in SQL. -

1 Respuestas

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 y la 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.

Respondido 02 Feb 12, 16:02

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.