$7
Customizing child item form with embedRelation doctrine
Hi,
I am using symfony 1.3 and doctrine 1.2.
I have an embedRelation setup, with order and order_item in a schema somewhat like below (i have abbreviated):
In a specific instance using my orders form and order_item form, I have created an embedRelation form to work with in a specific instance. I want to modify the orderItem listings in the embedRelation form so that it only displays product_id and price. However, presently when I update it, it overwrites "quantity" with blank value if I do not include it*. HOWEVER, I cannot modify orderItem form directly to unset values, as in other instances I need the full order_item form (at least this is what I have encountered thus far; perhaps someone else knows a better way).
I have lib/model/doctrine/OrderAssignForm.class.php
In form templates, I do (snippet of order item area)
But this causes quantity to be overwritten as null.
You *must* provide code to receive the award.
I am using symfony 1.3 and doctrine 1.2.
I have an embedRelation setup, with order and order_item in a schema somewhat like below (i have abbreviated):
Orders:
columns:
id: { type: integer(4), primary: true, autoincrement: true }
OrderItem:
columns:
id: { type: integer(4), primary: true, autoincrement: true }
order_id: { type: integer(4), primary: true, autoincrement: true }
product_id: { type: integer(4), primary: true, autoincrement: true }
quantity: { type: decimal(14) }
price: { type: decimal(10) }
relations:
Order: { local: order_id, foreign: id }
Product: { local: product_id, foreign: id }
Product:
columns:
id: { type: integer(4), primary: true, autoincrement: true }
name: { type: string(150) }
In a specific instance using my orders form and order_item form, I have created an embedRelation form to work with in a specific instance. I want to modify the orderItem listings in the embedRelation form so that it only displays product_id and price. However, presently when I update it, it overwrites "quantity" with blank value if I do not include it*. HOWEVER, I cannot modify orderItem form directly to unset values, as in other instances I need the full order_item form (at least this is what I have encountered thus far; perhaps someone else knows a better way).
I have lib/model/doctrine/OrderAssignForm.class.php
class OrderAssignForm extends OrdersForm
{
public function configure()
{
$this->embedRelation('OrderItem');
}
}
In form templates, I do (snippet of order item area)
<form action="<?php echo url_for('order_assign').'?id='.$form->getObject()->getId()?>">
<?php echo $form->renderHiddenFields() ?>
<?php echo $form->renderGlobalErrors() ?>
<?php foreach ($form['OrderItem'] as $oi): ?>
<?php echo $oi->renderHiddenFields() ?>
<?php echo $oi['product_id']?>
<?php echo $oi['price']->renderError() ?>
<?php echo $oi['price'] ?><br/>
<?php endforeach; ?>
But this causes quantity to be overwritten as null.
You *must* provide code to receive the award.
webguy | 05/27/10 at 8:33am
| Edit
(1) Possible Answers Submitted...
-

Last edited:
05/27/10
9:25amWojciech Sznapka says:Use inheritance :-)
Create EmbedOrderItemForm in lib/form/doctrine in which you will customize it, and then use as embedded form
class EmbedOrderItemForm extends OrderItemForm
{
public function configure()
{
$this->useFields(array('displays product_id, 'price'));
}
}
when embeding relation remember to pass form class:
$this->embedRelation ('OrderItem', 'EmbedOrderItemForm');
Previous versions of this answer: 05/27/10 at 8:43am
- 05/27/10 9:25am
webguy says:Of course! I was trying to do this, just didn't know the syntax. Thank you!
- 05/27/10 9:25am
This question has expired.
Current status of this question: Completed





