[eluser]thevenin[/eluser]
sHiRoKKo1337 thank you for your contribution.
I found the answer on phpactiverecord official forum:
Code:
class Match extends ActiveRecord\Model {
static $table_name = 'matches';
static $belongs_to = array(
array('home_team', 'class'=>'Team','foreign_key'=>'home_team_id'),
array('away_team', 'class'=>'Team','foreign_key'=>'away_team_id')
);
}
Code:
class Team extends ActiveRecord\Model {
static $has_many = array(
array('home_matches', 'class'=> 'Match'),
array('away_matches', 'class'=> 'Match')
);
}
In the controller:
Code:
class Matches extends MY_Controller
{
function index()
{
$this->output->enable_profiler(TRUE);
$this->view_data['matches'] = Match::find('all');
}
}
and finally in the index.php view:
Code:
<?foreach($matches as $match):?>
<li><?=$match->home_team->name?> - <?=$match->away_team->name?></li>
<?endforeach?>
Best regards.