1
我:設置多對多關係
@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
什麼excatly你想幹什麼?我們可以看到你的schema.yml嗎?只是User,UserGroups和User的一部分。如果模式是正確的,我不認爲你會有任何問題。 – bertzzie
用戶沒有名爲UsersGroups的屬性,您可以將其設置爲2.它具有相關UsersGroups對象的集合(所有那些user_id是此用戶的行)......將其設置爲數字2是沒有意義的無論是。 –