CActiveRecord relations between different modules

Hi,

I’ve got the problem described below.

STRUCTURE

- Module user: [color="#4169E1"]protected/modules/user[/color]


    - CActiveRecord Model [color="#4169E1"]protected/modules/user/models/User.php[/color]


- Module games: [color="#4169E1"]protected/modules/games[/color]


    - CActiveRecord Model [color="#4169E1"]protected/modules/games/models/Game.php[/color]

RELATIONS

In the User Model, I’ve got this relation entry inside the relations() method:




'game' => array(self::HAS_ONE, 'Game', 'user_id'),



In the Game Model, I’ve got this relation entry inside the relations() method:




'user' => array(self::BELONGS_TO, 'User', 'user_id'),



PROBLEM

When trying to access:


$model->game->name

from my user’s views, I got the following error:

[color="#FF0000"]include(Game.php) [<a href=‘function.include’>function.include</a>]: failed to open stream: No such file or directory[/color]

OK, I must correct the path, I thought. So I tried this:




'game' => array(self::HAS_ONE, 'application.modules.games.models.Game', 'user_id'),



but I received the same error:

[color="#FF0000"]include(application.modules.games.models.Game.php) [<a href=‘function.include’>function.include</a>]: failed to open stream: No such file or directory[/color]

What am I missing? ???

Bye,

Andrea

I think you should import the class before you can specify it in relations():




// protected/modules/user/models/User.php

Yii::import('application.modules.games.models.Game', true);



Thank you, andy_s. :)

In the meanwhile I solved in a way which I think is really in the same direction you point out.

I added an import entry to the setImport() method of the UserModule class (the CWebModule main class of the user module), pointing to the games module models folder:




public function init()

{

	// this method is called when the module is being created

	// you may place code here to customize the module or the application


	// import the module-level models and components

	$this->setImport(array(

		'user.models.*',

		'user.components.*',

		'application.modules.games.models.*',

	));

}



This works.

Thank you and bye :)