设置多对多关系
我有:
@method Users setMail() Sets the current record's "mail" value
@method Users setUsersGroups() Sets the current record's "UsersGroups" collection
public function save(Doctrine_Connection $conn = null) {
if($this->isNew()) {
$this->setMail('[email protected]')); // ok
$this->setUsersGroups(2); // doesn't work - error Couldn't call Doctrine_Core::set(), second argument should be an instance of Doctrine_Collection when setting one-to-many references.
}
parent::save($conn);
}
表 UsersGroups:
user_id
group_id
这是多对多关系。
如何为组设置用户?
示例架构:
Users:
columns:
id:
type: integer(4)
autoincrement: true
primary: true
mail:
type: string(255)
password:
type: string(255)
attributes:
export: all
validate: true
Group:
tableName: group_table
columns:
id:
type: integer(4)
autoincrement: true
primary: true
name:
type: string(255)
relations:
Users:
foreignAlias: Groups
class: User
refClass: GroupUser
UsersGroups:
columns:
group_id:
type: integer(4)
primary: true
user_id:
type: integer(4)
primary: true
relations:
Group:
foreignAlias: UsersGroups
Users:
foreignAlias: UsersGroups
I have:
@method Users setMail() Sets the current record's "mail" value
@method Users setUsersGroups() Sets the current record's "UsersGroups" collection
public function save(Doctrine_Connection $conn = null) {
if($this->isNew()) {
$this->setMail('[email protected]')); // ok
$this->setUsersGroups(2); // doesn't work - error Couldn't call Doctrine_Core::set(), second argument should be an instance of Doctrine_Collection when setting one-to-many references.
}
parent::save($conn);
}
Table UsersGroups:
user_id
group_id
this is many to many relations.
how can i set users for groups?
example schema:
Users:
columns:
id:
type: integer(4)
autoincrement: true
primary: true
mail:
type: string(255)
password:
type: string(255)
attributes:
export: all
validate: true
Group:
tableName: group_table
columns:
id:
type: integer(4)
autoincrement: true
primary: true
name:
type: string(255)
relations:
Users:
foreignAlias: Groups
class: User
refClass: GroupUser
UsersGroups:
columns:
group_id:
type: integer(4)
primary: true
user_id:
type: integer(4)
primary: true
relations:
Group:
foreignAlias: UsersGroups
Users:
foreignAlias: UsersGroups
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)