0
class Games{
    var $has_many = array('gameSetting','team','log');
}

class GameSetting {}

class Team{
    var $has_many = array('user','log');
}
class User {
    var $has_many = array('log');
}

class Log {
}

According to the official document, With out joining tables I must create the suffix _id act as the foreign key. So in the logs table There are 3 foreign keys game_id,team_id,user_id.

How should I name the FK column and How Datamapper know which FK is reference to which table with the same suffix _id?

Runicer
  • 71
  • 2
  • 13

1 Answers1

1

First of all you need to make sure your relationships are properly configured. This means defining the relationship in both models concerned (http://datamapper.wanwizard.eu/pages/settingrelations.html).

So your Log model should look like this:

class Log extends DataMapper {
    var $has_one = array('game','team','user');
}

The logs table then simply needs the columns 'game_id', 'team_id' and 'user_id' -- DataMapper will know where to look to populate the related objects.

It's all explained clearly in the docs (look under 'In-Table Foreign Keys'): http://datamapper.wanwizard.eu/pages/database.html

froddd
  • 363
  • 1
  • 8