I'm having what should be a simple problem with Symfony.
In this example I have a User, LookingFor, and LookingForNames table. The user table holds the user account and has a relation with LookingFor. The LookingFor table holds any relations between a user and the LookingForNames.
Example: The user 'chain', could have two entries in the LookingFor table for dating and talk, which are looked up from the LookingForNames table based on the type_id from LookingFor and LookingForNames.
The problem I am having is when I embedRelation for LookingFor within the User form. It's showing the LookingFor form twice because the user has selected they are looking for dating and talk. It would show up more times if I have more selected for that user.
eg. of the problem
LookingFor Form - Instance #1
Dating - Checked
Talk - Not Checked
Friends - Not Checked
LookingFor Form - Instance #2
Dating - Not Checked
Talk - Checked
Friends - Not Checked
The solution would be showing the LookingFor table once in a checkbox format where the user's selection would be preselected.
eg. of the 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
));
}
}