huss
(huss@tahn.biz)
January 25, 2014, 4:21am
1
My relation seems to be selecting the correct records but they are empty.
Model:
public function relations() {
return array(
'subscribersResources' => array(self::HAS_MANY, 'SubscribersResources', array('id_subscriber'=>'id')),
'resources' => array(self::HAS_MANY, 'Resources', array('id_resource'=>'id'), 'through' => 'subscribersResources'),
);
}
Controller:
/**
* @param string
* @return string
* @soap
*/
public function getResources($userId) {
$subscriber = Subscribers::model()->findByPk($userId);
$response = $subscriber->resources;
return json_encode($response);
}
Returns
Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) [3] => Array ( ) [4] => Array ( ) )
perochak
(Amjad Mughal)
January 25, 2014, 4:44am
2
Seems that your subscribersResources are not being populated. check results of the that relation
huss
(huss@tahn.biz)
January 25, 2014, 4:56am
3
That array is also empty. Why would this be though? It seems to be correct, what can I do to check?
public function relations(){
return array(
'subscribersResources' => array(self::HAS_MANY, 'SubscribersResources', 'id_subscriber'),
'resources' => array(self::HAS_MANY, 'Resources', array('id_resource'=>'id'), 'through' => 'subscribersResources'),
);
}
huss
(huss@tahn.biz)
January 28, 2014, 8:03am
4
Can anyone help?? It sounds so straight forward, it should work. PLEASE HELP!!
argent
(Argent Hun)
January 28, 2014, 9:25am
5
try this:
return CJSON::encode($response);
instead of
return json_encode($response);
shivg
(Gaikwad411)
January 28, 2014, 9:43am
6
Your relations config is correct. I have tried this.
For me it returns array of object. Try to check the
var_dump($subscriber->resources)
it should
return array of object.
One more thing.
Your function should return json encoded string as output, but the output you have written is not json encoded string.
huss
(huss@tahn.biz)
January 28, 2014, 12:12pm
7
shivg:
Your relations config is correct. I have tried this.
For me it returns array of object. Try to check the
var_dump($subscriber->resources)
it should
return array of object.
I will try var_dump I’m using print_r, I don’t think it will make a difference may shed some light perhaps?
That’s because I decoded in the view file. Sorry should have explained that.
huss
(huss@tahn.biz)
January 28, 2014, 12:22pm
8
One of the tables was MyISAM type, the rest are InnoDB. I’ve corrected now so they are all InnoDB. I thought this might have been the cause but still have the same problem.
I read in another post that a good check is to run just plain SQL query to rule out the DB as the cause.