Answers.Body: <p>I'm not sure this is the answer Drew is looking for or it even addresses his issue.  It sounds like it was working for him and then he had a timeout and it messed a number of them up.  The comments, which I added too many to, show that it doesn't work in some cases.</p>
  
  <p>To import contact with a master address belonging to someone else, you need to include the actual address along with the address belongs to.  It is looking for the ID of master address.  How one might know that without sql is beyond me.  Whenever I've imported people with shared addresses, I've imported all the people each with an address and then wrote some sql to pull out the address id of those that would be the master and id of the contact that would use that address and id and did an import update.</p>
  
  <p>I just imported a Joe Blow into Demo46 having him share an address id 3.  My cvs had first, last, street, city, state, postal, country and master address belongs to.  </p>
  
  <p>I'm guessing way back when for ease of implimenting shared addresses it appears it was decided not to quite do them as relational database should.  You'd expect the id to be there and for the forms, queries, etc. to follow that id for the address, but it appears it depends on the address actually being in the record.  I suspect the contact form sees that and does a copy when you share an address or the master gets changed.</p>
  
  <p>So Drew you might look at your database and see if you have records in civicrm_address that have a master address id but the street, city, etc. are blank.  If so this sql should fix it.  (A caution, I wrote this sql a while ago but it think it's still fine.  In case your wondering why it is ca and pa, I was dealing parents and children.)</p>
  
  <pre><code>update civicrm_address ca,
         civicrm_address pa
  set    ca.street_address = pa.street_address,
         ca.city = pa.city,
         ca.state_province_id = pa.state_province_id,
         ca.postal_code = pa.postal_code,
         ca.postal_code_suffix = pa.postal_code_suffix,
         ca.country_id = pa.country_id
  where  ca.master_id = pa.id
  and    ca.master_id is not null
  and    ca.street_address is null
  </code></pre>
  
  <p>If you don't have the master_id populated but you do have the two people both having the address, you could write some sql to add the address id of the first to be the master_id of the second.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-13T03:21:04.643Z
Answers.LastActivityDate: 2016-03-13T03:21:04.643Z
Answers.UserDisplayName: Paul-Tahoe
Body: <p>I have been working to finalize import of approximately 2,000 contact records from our old systems. Our old db had 2 people in one record, so have been working to separate. Imported the primary contact and was using import on the second contact and utilize the "master address belongs to" field. My 2 smaller groups of the second contact worked just fine and properly "mapped" and saved the master addressee belongs to. Yesterday I was importing my last batch of about 600 names. The import took longer than normal but eventually I just went to a screen saying there was a web server error. About 94 of the last records didn't get imported. As I was working on some cleanup I realized that when I would manually go edit someone's address and tie it to a master address nothing would save. I was able to take one contact, put in an address, save, and then edit again and tie the master address. However, I haven't been able to replicate that again. I ran the system job to clean cache and that didn't help. I was on 4.6.5 and decided to go ahead and do my upgrade yesterday to see if that might clear up whatever, and it didn't. The crash of the import seems to be the point where something changed. Has anyone experienced this or recommend anything (even at the table level in phpMyAdmin -- which I am comfortable navigating in) that I can check/try?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-13T02:21:29.860Z
Comments.Text: I'm not sure this has ever worked quite right.  I believe the only way I've been able to import contacts and master addresses was a two step process.  1. import person including the street, city, etc of the master address.  2.  import update adding the master address belongs to.  When an address record has a master address id, it also has the street, city, etc.
Comments.UserDisplayName: Paul-Tahoe
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-13T02:22:26.567Z
Comments.Text: If you try to import update a person without an address and include the master address belongs to, the contact will appear not to have an address.  When you click on the address it will pull up all the addresses in the db.   If you try to import update a person without an address and include the master address belongs to, the contact will appear not to have an address.  When you click on the address it will pull up all the addresses in the db.
Comments.UserDisplayName: Paul-Tahoe
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-13T02:27:54.797Z
Comments.Text: When I tried to import a new person with a master address belongs to with debug on I got a back trace, is not of the type Integer coming from CRM_Contact_BAO_Relationship::checkDuplicateRelationship((Array:4), 8861, NULL).  That last NULL can't be null.  It should be the ID of the master address's contact.  The code looks to be trying to create relationships in the case of individual having the master address of a household.
Comments.UserDisplayName: Paul-Tahoe
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-09T12:38:37.217Z
Comments.Text: I just tried something that may be indicating why an update isn't saving. If I just go to a contact and click the Edit Address button in the address area, Civi lets me select another user but nothing saves (i.e.,the address comes back to the one already entered and isn't linked). I found another similar post and he stated that he if went to the full edit instead he got some resolution. I tried that with 2 contacts and in both cases when entering different contacts (that have an address on their record), Civi threw "Please select valid shared contact or a contact with valid address" when saving
Comments.UserDisplayName: Drew
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-10T20:50:40.737Z
Comments.Text: not sure if this will help but - can you visit civicrm/admin/setting/debug?reset=1 and turn on debugging and backtrace. And yes try using the full 'Edit' process. Also note if you get pop ups and do not see any useful errors, rather than just clicking on the button that triggers the pop up, try right clicking and opening in a new page, since that is more likely to show you any errors.
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-28T15:56:22.917Z
Comments.Text: I tried to import a "Master Address belongs to" using http://d46.demo.civicrm.org/ and it will not import. Unless somebody can share the steps to get this to work on the demo site, we should consider this feature broken and report a bug.
Comments.UserDisplayName: LunkRat
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-09-03T22:19:18.800Z
Comments.Text: hmm - i tried importing a Master Address too and got nowhere. Would you be willing to open a JIRA ticket, spell out steps to replicate. and then perhaps post the jira as an answer here
Comments.UserDisplayName: petednz - fuzion
Tags: <contacts><import>
Title: Master address - not saving choice
ThreadText: # Master address - not saving choice
  
  (Asked by: username_0 on 2015-08-09)
  
  I have been working to finalize import of approximately 2,000 contact records from our old systems. Our old db had 2 people in one record, so have been working to separate. Imported the primary contact and was using import on the second contact and utilize the "master address belongs to" field. My 2 smaller groups of the second contact worked just fine and properly "mapped" and saved the master addressee belongs to. Yesterday I was importing my last batch of about 600 names. The import took longer than normal but eventually I just went to a screen saying there was a web server error. About 94 of the last records didn't get imported. As I was working on some cleanup I realized that when I would manually go edit someone's address and tie it to a master address nothing would save. I was able to take one contact, put in an address, save, and then edit again and tie the master address. However, I haven't been able to replicate that again. I ran the system job to clean cache and that didn't help. I was on 4.6.5 and decided to go ahead and do my upgrade yesterday to see if that might clear up whatever, and it didn't. The crash of the import seems to be the point where something changed. Has anyone experienced this or recommend anything (even at the table level in phpMyAdmin -- which I am comfortable navigating in) that I can check/try?
  
  **Tags:** contacts, import
  
  > **Comments:**
  > **username_0**: I just tried something that may be indicating why an update isn't saving. If I just go to a contact and click the Edit Address button in the address area, Civi lets me select another user but nothing saves (i.e.,the address comes back to the one already entered and isn't linked). I found another similar post and he stated that he if went to the full edit instead he got some resolution. I tried that with 2 contacts and in both cases when entering different contacts (that have an address on their record), Civi threw "Please select valid shared contact or a contact with valid address" when saving  
  > **username_2**: not sure if this will help but - can you visit civicrm/admin/setting/debug?reset=1 and turn on debugging and backtrace. And yes try using the full 'Edit' process. Also note if you get pop ups and do not see any useful errors, rather than just clicking on the button that triggers the pop up, try right clicking and opening in a new page, since that is more likely to show you any errors.  
  > **username_3**: I tried to import a "Master Address belongs to" using http://d46.demo.civicrm.org/ and it will not import. Unless somebody can share the steps to get this to work on the demo site, we should consider this feature broken and report a bug.  
  > **username_2**: hmm - i tried importing a Master Address too and got nowhere. Would you be willing to open a JIRA ticket, spell out steps to replicate. and then perhaps post the jira as an answer here  
  > **username_1**: I'm not sure this has ever worked quite right.  I believe the only way I've been able to import contacts and master addresses was a two step process.  1. import person including the street, city, etc of the master address.  2.  import update adding the master address belongs to.  When an address record has a master address id, it also has the street, city, etc.  
  > **username_1**: If you try to import update a person without an address and include the master address belongs to, the contact will appear not to have an address.  When you click on the address it will pull up all the addresses in the db.   If you try to import update a person without an address and include the master address belongs to, the contact will appear not to have an address.  When you click on the address it will pull up all the addresses in the db.  
  > **username_1**: When I tried to import a new person with a master address belongs to with debug on I got a back trace, is not of the type Integer coming from CRM_Contact_BAO_Relationship::checkDuplicateRelationship((Array:4), 8861, NULL).  That last NULL can't be null.  It should be the ID of the master address's contact.  The code looks to be trying to create relationships in the case of individual having the master address of a household.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-03-13. Score: 1
  
  I'm not sure this is the answer username_0 is looking for or it even addresses his issue. It sounds like it was working for him and then he had a timeout and it messed a number of them up. The comments, which I added too many to, show that it doesn't work in some cases.
  
  To import contact with a master address belonging to someone else, you need to include the actual address along with the address belongs to. It is looking for the ID of master address. How one might know that without sql is beyond me. Whenever I've imported people with shared addresses, I've imported all the people each with an address and then wrote some sql to pull out the address id of those that would be the master and id of the contact that would use that address and id and did an import update.
  
  I just imported a Joe Blow into Demo46 having him share an address id 3. My cvs had first, last, street, city, state, postal, country and master address belongs to.
  
  I'm guessing way back when for ease of implimenting shared addresses it appears it was decided not to quite do them as relational database should. You'd expect the id to be there and for the forms, queries, etc. to follow that id for the address, but it appears it depends on the address actually being in the record. I suspect the contact form sees that and does a copy when you share an address or the master gets changed.
  
  So username_0 you might look at your database and see if you have records in civicrm\_address that have a master address id but the street, city, etc. are blank. If so this sql should fix it. (A caution, I wrote this sql a while ago but it think it's still fine. In case your wondering why it is ca and pa, I was dealing parents and children.)
  
  ```
  update civicrm_address ca,
         civicrm_address pa
  set    ca.street_address = pa.street_address,
         ca.city = pa.city,
         ca.state_province_id = pa.state_province_id,
         ca.postal_code = pa.postal_code,
         ca.postal_code_suffix = pa.postal_code_suffix,
         ca.country_id = pa.country_id
  where  ca.master_id = pa.id
  and    ca.master_id is not null
  and    ca.street_address is null
  
  ```
  
  If you don't have the master\_id populated but you do have the two people both having the address, you could write some sql to add the address id of the first to be the master\_id of the second.
  
  
  ---
  
  