Je rencontre ce qui devrait être un problème simple avec Symfony.Symfony un-à-plusieurs embedrelation montrant plusieurs formes
Dans cet exemple, j'ai une table User, LookingFor et LookingForNames. La table utilisateur contient le compte d'utilisateur et a une relation avec LookingFor. La table LookingFor contient toutes les relations entre un utilisateur et les LookingForNames. Exemple: L'utilisateur 'chain', pourrait avoir deux entrées dans la table LookingFor pour la datation et la discussion, qui sont recherchées dans la table LookingForNames basée sur le type_id de LookingFor et LookingForNames.
Le problème que j'ai est quand je embedRelation pour LookingFor dans le formulaire d'utilisateur. Il affiche deux fois le formulaire LookingFor car l'utilisateur a choisi de rechercher et de discuter. Il apparaîtrait plus de fois si j'avais plus de choix pour cet utilisateur.
par ex. du problème
LookingFor Form - Instance #1
Dating - Checked
Talk - Not Checked
Friends - Not Checked
LookingFor Form - Instance #2
Dating - Not Checked
Talk - Checked
Friends - Not Checked
La solution présentera la table de lookingfor une fois dans un format de case où serait présélectionné la sélection de l'utilisateur.
par ex. de la solution
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
class 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
));
}
}