简体   繁体   English

Rails 3.2:(activerecord)我该如何建模?

[英]Rails 3.2 : (activerecord) How do I model this?

在此处输入图片说明

I have three models: RequestForQuote , CounterQuote < RequestForQuote [inherit RequestForQuote] and Proposition . 我有三个模型: RequestForQuoteCounterQuote < RequestForQuote [inherit RequestForQuote]Proposition

A request_for_quote has_many propositions , and a proposition can act as a tree with a counter_quote . request_for_quote propositions ,并且该proposition可以充当带有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. CounterQuote的属性propositionpropositions不太清楚,请考虑对其重命名。

If CounterQuote can have many propositions, I agree with Tass, you can merge CounterQuote and RequestForQuote. 我同意Tass的观点,如果CounterQuote可以有很多主张,那么您可以合并CounterQuote和RequestForQuote。 If you need a tree structure (with parent and children), look at existing gems like awesome_nested_set . 如果您需要树结构(包括父级和子级),请查看现有的宝石,例如awesome_nested_set

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM