Join in Model ... Required Suggestions


#1

HI,

Since Update template does not support join… Need help in the following

Following is my table structure

users(id,name)
members(id,user_id,mobile_no)
distributor(id,member_id,code)

Now I want Distributor Model joined with members and users …
psudo code :smile:

class Model_Distributor extends SQL_Model {
function init(){
parent::init();

$this->addField('code');
$member_join = $this->join('members','member_id');
$member_join->addField('mobile_no');

$user_join = $member_join->join('users','user_id');
$user_join->addField('name');

}

but join is executing in following sequence
member query first => user query => distributor query
So… No User entry in member table

Second try

I added user_id and member_id in distributor table

users(id,name)
members(id,user_id,mobile_no)
distributors(id,user_id,member_id,code)

in init of Distributor model

$this->addField('code');

$user_join = $this->join('users','user_id');
$user_join->addField('name');

$member_join = $this->join('members','member_id');
$member_join->addField('mobile_no');

This works okey and distributor table gets Id of user and member but now member does not gets user_id in it

If I add another join with user and member … system does a third entry !!!

Any suggestions …


#2

just a quick reply. Relations execute update on proper table when saving.

I can look into your issue in more details a bit later.


#3

I like Agile Toolkit framework :blush: