• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DataMapper ORM relations problem

#1
[eluser]Unknown[/eluser]
Hi.

I've started testing DataMapper ORM and ran into a little problem with relations. I have following tables and relations.
Code:
class Bet extends DataMapper {
    var $auto_populate_has_one = TRUE;
    var $has_many = array();
    var $has_one = array('user', 'game');
}
class Winning_bet extends DataMapper {
    var $auto_populate_has_one = TRUE;
    var $has_many = array();
    var $has_one = array('game', 'user');
}
class User extends DataMapper {
    var $has_many = array('bet', 'winning_bet');
    var $has_one = array();
}
class Prize extends DataMapper {
    var $has_one = array();
    var $has_many = array('game');
}
class Game extends DataMapper {
    var $auto_populate_has_one = TRUE;
    var $has_many = array('bet');
    var $has_one = array('winning_bet', 'prize');
}

I can get users winning bets like this.
Code:
$u = $this->login_manager->get_user();//Returns current logged in user
$u->winning_bet->get_iterated();

I would like to get game related to that winning_bet. I have only managed to get this by turning auto_populate to true in Winning_bet model. This applies to every relation I have in that model and it will cause problems when I only want specific data to be populated. Also I have user in every has_one relation that is auto-populated which causes user to be fetched again.

So what would be appropriate way to get game related to Winning_bet? I'm sure there is pretty simple solution for my problem but at the moment I can't figure out any solution.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.