Hi everyone. Actually I didn’t get the how to work with ORM.

I had tables



Agent Profile

Agent files

Agent has one to one relation to agent profile and agent has HAS_MANY relation to property

the relation whould something like that


It means I am trying to access to get acess to the agent files standing on the agent module i,e I am trying to get child property win parents modules which throw message as trying to get non object property

It means we can’t get access to the child data from parent table. Is am I right or wrong please help me out.


if I got it right you want to select all agents with their files, so you should look into through relation.

In your Agent model:

public function relations()


		return array(

			'agent_profiles'=>array(self::HAS_MANY, 'AgentProfile','agent_id'),

			'agent_files'=>array(self::HAS_MANY, 'AgentFiles', array('agent_id'=>'id'),'through'=>'agent_profiles'),



use it as:

$agents = Agent::model()->with('agent_profiles', 'agent_files')->findAll();

In you view:

foreach($agents as $agent)

	foreach($agent->agent_files as $agent_file)


Hope it helps

[color="#008000"]NOTE: moved topic to proper section (General Discussion for Yii 1.1.x instead of Job Opportunities)[/color]