我有什麼應該是與Symfony的一個簡單的問題。Symfony一對多嵌入顯示多種形式
在這個例子中,我有一個User,LookingFor和LookingForNames表。用戶表保存用戶帳戶並與LookingFor關聯。 LookingFor表格包含用戶和LookingForNames之間的任何關係。
示例:用戶'鏈'可能在LookingFor表中有兩個條目用於約會和談話,這些條目是基於來自LookingFor和LookingForNames的type_id從LookingForNames表查找的。
我遇到的問題是當我在用戶表單中查找嵌入關係時。它顯示兩次LookingFor表單,因爲用戶已選擇他們正在尋找約會和交談。如果我爲該用戶選擇了更多選項,則會顯示更多次。
例如。問題
LookingFor Form - Instance #1
Dating - Checked
Talk - Not Checked
Friends - Not Checked
LookingFor Form - Instance #2
Dating - Not Checked
Talk - Checked
Friends - Not Checked
的溶液將被示出LookingFor表一次在一個複選框格式,其中用戶的選擇將被預選。
例如。溶液
LookingFor Form - Only One Instance
Dating - Checked
Talk - Checked
Friends - Not Checked
的schema.yml
LookingFor:
connection: doctrine
tableName: looking_for
columns:
type_id:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: false
uid:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: false
relations:
LookingForNames:
local: type_id
foreign: type_id
type: many
LookingForNames:
connection: doctrine
tableName: looking_for_names
columns:
type_id:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: true
name:
type: string(255)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
relations:
LookingFor:
local: type_id
foreign: type_id
type: many
User:
connection: doctrine
tableName: user
columns:
id:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: true
email:
type: string(255)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
gender:
type: string(6)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
age:
type: date(25)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
city:
type: string(255)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
state:
type: string(255)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
country:
type: integer(4)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
profilepic:
type: string(255)
fixed: false
unsigned: false
primary: false
default: profileblank.jpg
notnull: false
autoincrement: false
relations:
LookingFor:
local: id
foreign: uid
type: many
foreignType: many
UserEditForm
class UserEditForm extends BaseUserForm
{
public function configure()
{
$this->embedRelation('LookingFor');
}
}
LookingForForm
的3210class LookingForForm extends BaseLookingForForm
{
public function configure()
{
$this->useFields(array('type_id'));
$this->widgetSchema['type_id'] = new sfWidgetFormChoice(array(
'choices' => Doctrine_Core::getTable('LookingForNames')->getFormChoiceNames(),
'expanded' => true,
'multiple' => true
));
}
}