0

I have 3 models in my test Rails 4 project.

  1. Company
  2. Project
  3. Contact

A Company has_many Contacts and has_many Projects. A Project belongs_to a Company. A Contact belongs_to a Company.

I want to be able to create a relationship between a Project and a Contact. There is the option to use the has_many :through relation but this will display all the Companies Contacts or Projects.

If I create a separate HABTM table i won't be able to use the "dependent: :destroy" option.

How can i make the relationship and let it be dependent on the company? So when i change the Contacts related company i won't have any corrupt data in my DB and all old relationships will be destroyed.

Eelco
  • 111
  • 1
  • 7
  • Project `has_many :contacts, :through => :company` should return only contacts of the company's project. – pierallard Oct 21 '14 at 16:33
  • Yes, i agree. But i can not set only certain contacts for the project this way. This will give me all Contacts for the Project. When creating or editing a Project i want to be able to select the contacts. When creating or editing a Contact i want to be able to select the projects. – Eelco Oct 21 '14 at 18:25

0 Answers0