开发者

'Company' and 'Person': threat them similar... but gives problems when creating forms

Our company can have a contract with a person and a company.

So the responsible 'party' of a contract, can be both a person and a company.

I have setup a model where:

---

Contract ------ person | -- company

class Contract < ActiveRecord::Base belongs_to :party, :polymorphic => true end

class Party < ActiveRecord::Base self.abstract_class = true has_many :contracts, :as => :party end

class Organization < Party end

class Person < Party end

---

What I wan开发者_JAVA百科t to be able to do is have a form "new contract" and in the field "contract with" I'd like to have a dropdown box of all known people and companies.

---

In the end: I'm willing to change my model and ideas... but the behaviour that should remain is that a contract can be closed with both a person and a company. Any suggestion is welcome!


You could fill your select values with a string containing both class and id (i.e. ), which you then process in either the model or controller.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜