Quote:Resolved. Duh! What a moron I'am Country should ofcourse be one-to-many with addressbooks! So changing $has_one = array('addressbook') to $has_many = array('addressbook') solved the problem. I'll crawl back to the cave now
Hi,
I have a problem saving relation addressbook->country.
Theres 3 tables, customers, addressbooks and countries. Customer can have several addressbooks, addressbooks can have single country. Problem is now that when I have 2 addressbooks and try to save the same country to both of them, other one gets wiped out!
First heres the update that DMZ is doing:
Quote:UPDATE `addressbooks` SET `country_id` = NULL WHERE `addressbooks`.`country_id` = 72 AND `addressbooks`.`id` <> '1'
UPDATE `addressbooks` SET `country_id` = 72 WHERE `id` = '1'
(so apparently it is first setting all addressbooks country_id to NULL with the same country_id)
And the code:
Code:
if ($this->input->post('save_address'))
{
$abook = new Addressbook();
$abook->get_by_id($this->input->post('addressbook_id'));
if ($abook->exists() && $this->data['customer']->id == $abook->customer_id)
{
$country = new Country();
$country->get_by_id($this->input->post('country'));
if ($country->exists())
{
$abook->from_array($_POST,array('name','company_name','company_id','address1','address2','zip','city'));