Welcome Guest, Not a member yet? Register   Sign In
Problem saving relation
#1

[eluser]Unknown[/eluser]
i have two following tables

"addresses" and "adresscategories".

"addresses" has one "adresscategories"

and

"addresscategories" has many "addresses"

There is a joining table for this

"addresscategories_addresses"


following is sql for these tables

CREATE TABLE `addresses` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`street_address` varchar(255) DEFAULT NULL,
`location_name` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8;

CREATE TABLE `addresscategories` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=24 DEFAULT CHARSET=utf8;

CREATE TABLE `addresscategories_addresses` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`address_id` int(11) DEFAULT NULL,
`addresscategory_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;


i have created the following models

// address.php
class Address extends DataMapper{
public $table= 'addresses';
public $has_one = array('Addresscategory' );


public function Address(){
parent:Big GrinataMapper();
}
}


//addresscategory.php
<?php
class Addresscategory extends DataMapper{

public $table = 'addresscategories';
public $has_many = array('Address');

public $validation = array(
array(
'field'=>'name',
'label'=>'Category Name',
'rules'=>array('required','trim'),
),
);

function Addresscategory(){
parent:Big GrinataMapper();
}

}






this is how i am trying to save this record in controller

$address = new Address();
$addressCategory = new Addresscategory();
$address->street_address = $this->input->post('street_address');
$address->location_name = $this->input->post('location_name');
$addressCategory->where('id',$this->input->post('address_category_id'))->get();

$address->save($addressCategory);

this is throughing error

An Error Was Encountered

Unable to relate addres with addresscategory.


what i am missing or doing wrong ?


Thanks

Rasikh Mashhadi
http://www.mashhadi.me


Messages In This Thread
Problem saving relation - by El Forum - 05-24-2011, 09:35 AM
Problem saving relation - by El Forum - 05-24-2011, 11:25 PM
Problem saving relation - by El Forum - 05-25-2011, 09:55 AM
Problem saving relation - by El Forum - 05-25-2011, 12:06 PM



Theme © iAndrew 2016 - Forum software by © MyBB