Hello,
im new on symfony - so i don't know, if my post is right here.
However - following szenario:
SCHEMA:
<code>
connection: propel
noXsd: false
defaultIdMethod: native
package: lib.model.family
classes:
Family:
tableName: family
columns:
id:
lastname: { type: varchar(255), required: true }
Pet:
tableName: pet
columns:
id:
kind: { type: varchar(255), required: true }
Family2Pet:
tableName: family2pet
columns:
family_id: { type: integer, primaryKey: true,
foreignReference: id, foreignTable: family, onDelete: cascade,
onUpdate: cascade, required: true }
pet_id: { type: integer, primaryKey: true,
foreignReference: id, foreignTable: pet , onDelete: cascade,
onUpdate: cascade, required: true }
</code>
Part of the generated BaseFamilyForm.class.php:
<code>
class BaseFamilyForm extends BaseFormPropel
{
...
protected function doSave($con = null)
{
parent::doSave($con);
$this->saveFamily2PetList($con);
}
public function saveFamily2PetList($con = null)
{
if (!$this->isValid())
{
throw $this->getErrorSchema();
}
if (!isset($this->widgetSchema['family2_pet_list']))
{
// somebody has unset this widget
return;
}
if (is_null($con))
{
$con = $this->getConnection();
}
$c = new Criteria();
$c->add(Family2PetPeer::FAMILY_ID, $this->object->getPrimaryKey
());
Family2PetPeer::doDelete($c, $con);
$values = $this->getValue('family2_pet_list');
if (is_array($values))
{
foreach ($values as $value)
{
$obj = new Family2Pet();
$obj->setFamilyId($this->object->getPrimaryKey());
$obj->setPetId($value);
$obj->save();
}
}
}
}
</code>
The problem is that the sfMixer::getCallables('BaseFamily:save:post')
is fired after Family is saved but before Family2Pet is saved. So get
old values for Family2Pet in the sfMixer-call.
The way to go better(may be) in BaseFamilyForm.class.php:
<code>
class BaseFamilyForm extends BaseFormPropel
{
...
protected function doSave($con = null)
{
$this->addFamily2PetList($con);
parent::doSave($con);
}
public function addFamily2PetList($con = null)
{
if (!$this->isValid())
{
throw $this->getErrorSchema();
}
if (!isset($this->widgetSchema['family2_pet_list']))
{
// somebody has unset this widget
return;
}
if (is_null($con))
{
$con = $this->getConnection();
}
$c = new Criteria();
$c->add(Family2PetPeer::FAMILY_ID, $this->object->getPrimaryKey
());
Family2PetPeer::doDelete($c, $con);
$values = $this->getValue('family2_pet_list');
if (is_array($values))
{
foreach ($values as $value)
{
$obj = new Family2Pet();
$obj->setPetId($value);
$this->object->addFamily2Pet($obj);
}
}
}
}
</code>
In this example i changed the saving logic for the 'family2_pet_list'-
widget. It is now added to the main object.
I did not realize any problems to go this way. is it possible to
update to this logic with the next symfony-releases?
Thanks for reading.
Toa...
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en
-~----------~----~----~----~------~----~------~--~---