Ok, now I have my validation working with a save I have a bit of a conundrum.

 

It doesn't look like cake fully supports transactions,

 

My Asset hasOne AssetData

 

The asset_data table has a foreign key asset_id back to the asset table.

 

To insert a complete asset, I need to insert a record in the asset table and in the asset_data table.

 

The code does this :

 

$this->data['Asset']['archive_state_id'] = 1;

                        $this->data['Asset']['asset_uri'] = "tbd/fakefolder";

                        $this->data['Asset']['active'] = 'y';

                       

                        if ($this->Asset->save($this->data))

                        {

                            $assetId = $this->Asset->getLastInsertId();

                           

                            $this->data['AssetData']['asset_id'] = $assetId;

                            

                           

                            if ($this->Asset->AssetData->save($this->data))

                            {

                                $this->flash("saved the asset", "/assets/add");

                            }

                            else

                            {

                                $this->flash("Unknown error trying to save asset", "/assets/add"); 

                               

                            }

 

The problem is if validation fails on my assetData then I will have already saved the asset record. The cake docs and some discussion did not recommened calling invalidates($this->data) from my model since save calls that before saving, but since there are no real transactions and I can’t rollback, should I just throw caution to the wind and directly call invalidates before saving the asset model so that if validation fails I’ll know before I’ve created an asset record ?

 

Thanks

Grant


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" 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/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply via email to