[eluser]Unknown[/eluser]
Hi everyone,
I've installed CI + DataMapper
When I save a simple Model, it's OK but when I try to save a Model related to another one, I got the error :
Quote:A Database Error Occurred
Error Number:
SELECT * FROM "VSR_COUNTRY_VEHICLE" WHERE "VEHICLE_ID" = '22' AND "COUNTRY_ID" = '24'
Filename: C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\data\localweb\VSR\system\database\DB_driver.php
Line Number: 330
CI is looking for a joining table VSR_COUNTRY_VEHICLE although it's a One-To-Many relationship
Here is my code :
Code:
class Vehicle_model extends DataMapper {
public $table = 'VEHICLE';
public $has_one = array(
'COUNTRY' => array(
'class' => 'country_model',
'other_field' => 'VEHICLE',
'join_other_as' => 'COUNTRY',
'join_table' => '',
'reciprocal' => FALSE,
'auto_populate' => NULL,
),
);
}
Code:
class Country_model extends DataMapper {
public $table = 'COUNTRY';
public $has_many = array(
'VEHICLE' => array(
'class' => 'vehicle_model',
'other_field' => 'COUNTRY',
'join_other_as' => 'VEHICLE',
'join_table' => '',
'reciprocal' => FALSE,
'auto_populate' => NULL,
),
);
}
and in the controller :
Code:
$a = new Vehicle_model();
$a->NAME = 'Ford';
$b = new Country_model();
$b->where('NAME', 'France')->get();
$a->save($b, 'COUNTRY');
Thanks
Vincent