Just updating and custom foreign key works perfectly.
But, I got one more question or maybe asking for a new feature. My table name contains prefix and suffix. Prefix is configurable via config.php which is
$config['my_db_prefix'] = 'qe_';
Also, my suffix is depends on user’s session data.
Below script can describe my problem (for simplicity I made my prefix and suffix has empty value).
This is models/wifes_gas.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Wifes extends Gas {
//public $table = 'wife';
public $relations = array(
'belongs_to' => array('user' => array()),
);
function __construct()
{
$prefix = ''; // just dummy for test purpose
$suffix = ''; // just dummy for test purpose
$CI =& get_instance();
//$prefix = $CI->load->config->item('my_db_prefix'); // to get prefix
//$suffix = $CI->tablename->get_suffix(); // to get suffix
$this->table = $prefix.'wife'.$suffix;
}
function _init()
{
}
}
And, this is my controller
$users = Gas::factory('user')->with('wifes')->all();
foreach($users as $single_user)
{
//var_dump($single_user->wifes);
echo $single_user->name;
$wife_name = ($single_user->wifes == FALSE) ? '' : $single_user->wifes->name; // dipakai bila menggunakan with('user_profiles');
echo ' - '.$wife_name;
echo '<br>';
}
If I run that controller, I can got all user’s name but without the wife’s name. Please help me
Many many thanks…