我刚刚创建了一个具有多对多关系(用户组)和以下代码的新项目。
正如您可以在代码中猜到的那样,我正在尝试将组手动分配给用户,但它没有分配任何东西......任何想法?
User:
columns:
id:
type: integer(4)
autoincrement: true
primary: true
username:
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
GroupUser:
columns:
group_id:
type: integer(4)
primary: true
user_id:
type: integer(4)
primary: true
relations:
Group:
foreignAlias: GroupUsers
User:
foreignAlias: GroupUsers
代码是这样的:
public function executeIndex(sfWebRequest $request)
{
$user = Doctrine_Core::getTable('User')->find(1);
$groups = Doctrine_Core::getTable('Group')->findAll();
$user->setGroups($groups);
$user->save();
$this->forward('default', 'module');
}