I have a problem in extracting data in a has_many relationship.
Before that, let me show you my database structure
Agent table
id
username
password
Views table
id
agent_id
accessor_id
An agent can allow a lot of agents to view their postings. The table view holds the data for agent owner and the agent that is allowed to view his/her posting.
My relation statement on view model is declared as followed:
/**
* @return array relational rules.
*/
public function relations() {
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'agents' => array(self::BELONGS_TO, 'Agent', 'agent_id'),
);
}
My relation statement on agent model is declared as followed:
/**
* @return array relational rules.
*/
public function relations() {
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'groups'=>array(self::BELONGS_TO, 'Group', 'group_id'),
'views' => array(self::HAS_MANY, 'View', 'agent_id'),
);
}
How can I retrieve data from the views table? I cannot do this with the following:
Assume that $obj is inside a foreach loop, looping an agent array data.
print_r($obj->views);