Problem saving relation |
[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:ataMapper(); } } //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:ataMapper(); } } 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
[eluser]Unknown[/eluser]
sounds like a bug in datamapper , report them , may be they will help
[eluser]bEz[/eluser]
Care to post your VIEW? Trying to help debug, but need to know how the data is being defined in the form code.
[eluser]bEz[/eluser]
Don't know what to say, but this worked for me... The PROFILER provided results for POST DATA and DATABASE QUERIES The changes I made are what you may want to concentrate your debugging on: (A) did not use form_validation->set_value(), instead just used the input->post() values. (B) did not use the models validation setup, and when I did, I changed the format you had originally. © I defined the name of the models below the naming of the table in each model file. (D) I MANUALLY ASSIGNED THE "address_category_id" because I'm not sure what YOU'RE VIEW file looks like. CONTROLLER Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); MODELS Code: <?php Code: <?php VIEW Code: <div class='mainInfo'> |
Welcome Guest, Not a member yet? Register Sign In |