Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom db entry for 3 way habtm in ROR
    primarykey
    data
    text
    <p>I am converting an existing perl gtk app into a ROR app</p> <p>I have a 3 way habtm association model.</p> <pre><code>class CustomerMaster &lt; ActiveRecord::Base has_and_belongs_to_many :address_master, :join_table =&gt; "customer_phone_addres" has_and_belongs_to_many :phone_master, :join_table =&gt; "customer_phone_address" class AddressMaster &lt; ActiveRecord::Base has_and_belongs_to_many :customer_master, :join_table =&gt; "customer_phone_addres" has_and_belongs_to_many :phone_master, :join_table =&gt; "customer_phone_addres" class PhoneMaster &lt; ActiveRecord::Base has_and_belongs_to_many :customer_master, :join_table =&gt; "customer_phone_addres" has_and_belongs_to_many :address_master, :join_table =&gt; "customer_phone_addres" </code></pre> <p>The join table has the following schema</p> <pre><code>CREATE TABLE customer_phone_address ( id bigserial NOT NULL, customer_master_id bigint, phone_master_id bigint, address_master_id bigint, CONSTRAINT customer_phone_address_pkey PRIMARY KEY (id), CONSTRAINT address FOREIGN KEY (address_master_id) REFERENCES address_master (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT customer FOREIGN KEY (customer_master_id) REFERENCES customer_master (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT phone FOREIGN KEY (phone_master_id) REFERENCES phone_master (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT uniq_cust_phone_address UNIQUE (customer_master_id, phone_master_id, address_master_id) ) </code></pre> <p>And I have created a nested form for customer_master#new which takes inputs for both address_master and phone_master</p> <p>Originally for the perl gtk app, only one entry is created in the join_table for each entry of customer, address and phone</p> <pre><code>id|customer_master_id|phone_master_id|address_master_id 186767|182774|500773|210683 </code></pre> <p>However using the above relationship model, I get two entries in case of ROR</p> <pre><code>id|customer_master_id|phone_master_id|address_master_id 186769|182810|500775|nil| 186770|182810|nil|211935| </code></pre> <p>I need to maintain backward compatibility to the perl gtk app. <strong>How do I get that single entry in the join table instead of the two entries?</strong></p> <p>I think this question is similar to <a href="https://stackoverflow.com/questions/5507150/custom-join-3-tables-usage-in-rails-2-3-8">https://stackoverflow.com/questions/5507150/custom-join-3-tables-usage-in-rails-2-3-8</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload