Have you considered an approach where you save A and B independently
(i.e. without worrying about the connecting ids), collecting the ids
of both A and B (using $this->A->id immediately after save) and then
doing a subsequent update?

On Dec 3, 7:54 am, Quess <[email protected]> wrote:
> @Miles J
> Your idea won't work with mysql and id field as autoincrement (dunno
> how with other db but i assume that can be the same).
> If you have 100 rows with id from 1 to 100 and you will delete last 5
> (from 96 to 100), then doing insert new rown you will get id 101, not
> 96.
>
> @DigitalDude
> Please take a look athttp://blog.jamiedoris.com/geek/560/
>
> Best Regards,
> Miro
>
> On Dec 3, 12:40 am, Miles J <[email protected]> wrote:
>
>
>
> > Its impossible to get the ID for a row your about to save, until after
> > you save it.
>
> > The most you can do is do a query to select the last row in the table,
> > then increment its ID by one.
>
> > On Dec 2, 2:18 pm, Dave <[email protected]> wrote:
>
> > > I think this would really help your situation
>
> > >http://bakery.cakephp.org/articles/view/wizard-component-1-2-1
>
> > > I have used it in the past and if you read the documentation thoroughly it
> > > is very easy to implement.
>
> > > On Wed, Dec 2, 2009 at 1:05 PM, DigitalDude 
> > > <[email protected]>wrote:
>
> > > > Hey,
>
> > > > I have a serious problem, and I need a hint from you guys to solve it!
>
> > > > In one of my controller actions, I have the problem that I need to
> > > > create some records , let's say A, B, and C.
>
> > > > The problem is, that record A needs a field from record B, which is
> > > > the ID of record B, and which I only can set when record A is saved,
> > > > and B is saved. In model C I need some information from the new
> > > > created models A and B, which I only have when model A and B are
> > > > saved.
>
> > > > As this has to do with a register-process for my app, I need to
> > > > validate the data for all models. The problem is, that when model A
> > > > passes validation, and get's saved (which is needed to save the other
> > > > models) and model B fails, I have a "never used" record of model A in
> > > > my database. I need to get around that, because that's like a worst
> > > > case for me!
>
> > > > I hope there's any chance to create a record, set this record with the
> > > > data I get from my registration form, and use the data for the other
> > > > records and save everything at the end of the action when every record
> > > > validates!
>
> > > > I know I can check a record for validation by setting the model data
> > > > with
>
> > > > $this->Model->set($this->data)
>
> > > > and then
>
> > > > if($this->Model->validates()) {
> > > >    ....save the record(s)
> > > > }
>
> > > > But right now I'm only able to do this when I have an edit action and
> > > > I set the Model to a specific record with like
>
> > > > $this->Model->id = $id_from_get_parameter_or_so
>
> > > > It would be VERY cool if there is a slight chance that I could create
> > > > a new record with current auto-increment id from the database, use
> > > > that id for my other models, and at the end when I created all needed
> > > > records I'd check every record for validation and if every record is
> > > > ok, they all get saved.
>
> > > > If anyone knows how to achieve this, I would be very very happy!
>
> > > > Cheers,
>
> > > > DD
>
> > > > P.S.:
>
> > > > If needed, I can post the code of the whole RequestAction to see if
> > > > maybe there's another solution to this...
>
> > > > Check out the new CakePHP Questions sitehttp://cakeqs.organdhelpothers
> > > > with their CakePHP related questions.
>
> > > > You received this message because you are subscribed to the Google 
> > > > Groups
> > > > "CakePHP" group.
> > > > To post to this group, send email to [email protected]
> > > > To unsubscribe from this group, send email to
> > > > [email protected]<cake-php%[email protected]
> > > >  om>For more options, visit this group at
> > > >http://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" 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?hl=en

Reply via email to