Symfony: embedRelation() controlling options for nesting multiple levels of relations
- by wulftone
Hey all,
I'm trying to set some conditional statements for nested embedRelation() instances, and can't find a way to get any kind of option through to the second embedRelation.
I've got a "Measure-Page-Question" table relationship, and I'd like to be able to choose whether or not to display the Question table. For example, say I have two "success" pages, page1Success.php and page2Success.php. On page1, I'd like to display "Measure-Page-Question", and on page2, I'd like to display "Measure-Page", but I need a way to pass an "option" to the PageForm.class.php file to make that kind of decision. My actions.class.php file has something like this:
// actions.class.php
$this-form = new measureForm($measure, array('option'=$option));
to pass an option to the "Page", but passing that option through "Page" into "Question" doesn't work.
My measureForm.class.php file has an embedRelation in it that is dependent on the "option":
// measureForm.class.php
if ($this-getOption('option') == "page_1") {
$this-embedRelation('Page');
}
and this is what i'd like to do in my pageForm.class.php file:
// pageForm.class.php
if ($this-getOption('option') == "page_1") { // Or != "page_2", or whatever
$this-embedRelation('Question');
}
I can't seem to find a way to do this. Any ideas?
Is there a preferred Symfony way of doing this type of operation, perhaps without embedRelation?
Thanks,
-Trevor
As requested, here's my schema.yml:
# schema.yml
Measure:
connection: doctrine
tableName: measure
columns:
_kp_mid:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: true
description:
type: string()
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
frequency:
type: integer(4)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
relations:
Page:
local: _kp_mid
foreign: _kf_mid
type: many
Page:
connection: doctrine
tableName: page
columns:
_kp_pid:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: true
_kf_mid:
type: integer(4)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
next:
type: string()
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
number:
type: string()
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
previous:
type: string()
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
relations:
Measure:
local: _kf_mid
foreign: _kp_mid
type: one
Question:
local: _kp_pid
foreign: _kf_pid
type: many
Question:
connection: doctrine
tableName: question
columns:
_kp_qid:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: true
_kf_pid:
type: integer(4)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
text:
type: string()
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
type:
type: integer(4)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
relations:
Page:
local: _kf_pid
foreign: _kp_pid
type: one