开发者

PHP Doctrine: generation problem?

I'm generating models from my Mysql db. It generates a foreign key collection properly, but not the other way around... Is this supposed to be 'by-design', or am i doing something wrong?

pseudo code alert

User:
  UserId pk
  LocationId fk     //User location

Location
  LocationId pk
  UserId fk         //Location owner

Generated code:

class User() {
    hasMany('Location') //for locations owned by the user

    //BUT N开发者_运维百科OT THIS ONE:
    //hasOne('Location_1') //for current location of user
}

class Location() {
    hasMany('User') //for users which are on that location

    //AND NOT THIS ONE
    //hasOne('User_1') //for location owner
}


You need to define an association table. Your pseudo code is misleading – in many to many relationship, no foreign keys are used in User or Location classes, but in association class.

See PDF manual page 76.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜