Hello guys,

I have been using the admin generator for quite some time and I just 
stumbled upon a limitation. Sometimes when using the admin generator you 
have your nice autogenerated Create/Edit form and everything looks fine 
unless you want to overwrite the executeEdit() method. Let me give an 
example.

I am using the sfPropelActAsNestedSetBehaviour and I have to make the 
new element either the root or the child of another node. So I did this 
in my executeEdit() method:

[php]
public function executeSave()
  {
    $this->store_catalog = $this->getStoreCatalogOrCreate();

    if ($this->getRequest()->getMethod() == sfRequest::POST)
    {
      try
      {
        $this->store_catalog->makeRoot();
        $this->store_catalog->save();
      }
      catch (Exception $e)
      {
        ;
      }
    }

    return parent::executeSave();
  }
[/php]


But this caused my form to created two new records in the database: one 
was the call of $this->store_catalog->save(); in my executeSave() and 
the other record was created by the call to parent::executeSave(); The 
long story short, the class method getStoreCatalogOrCreate() which is 
auto generated does not account for cases where $this->store_catalog 
already exists and always overwrites it thus creating a new record when 
$this->store_catalog is already a valid StoreCatalog object. I do not 
think I explained very well but this is as good as I can do it :)

This is that needs to be added to $this->getStoreCatalogOrCreate()

[php]
protected function getStoreCatalogOrCreate($id = 'id')
  {
    if ($this->store_catalog instanceof StoreCatalog) {
      return $this->store_catalog;
    }
    // then the rest of the code it is currently generated
  }
[/php]

I found a workaround to this problem by adding $_POST['id'] = 
$this->store_catalog->getId(); right after my call to 
$this->store_catalog->save() thus tricking the getStoreCatalogOrCreate() 
method to think that the form is submitted in order to edit the record 
and not to create it but I do not want to use such a workaround when I 
think a permanent solution can be implemented.

Do I need to explain some more?

Regards,
Kiril

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to