Re: Any chance to get the ID of a new created record BEFORE I save it to the DB?

2009-12-03 Thread Jeremy Burns
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 miroslaw.niepo...@gmail.com wrote:

Re: Any chance to get the ID of a new created record BEFORE I save it to the DB?

2009-12-03 Thread Jeremy Burns
I forgot to add... If the insert of B fails, you can delete A because you know the id of the most recently added row in A. On Dec 3, 8:32 am, Jeremy Burns jeremybu...@me.com wrote: Have you considered an approach where you save A and B independently (i.e. without worrying about the connecting

Re: Any chance to get the ID of a new created record BEFORE I save it to the DB?

2009-12-03 Thread DigitalDude
Hey, @Jeremy: That's what I did after few tries. I set the fields where I need foreign keys to static values, checked the user-input of every model with $this-model-validates() and if sth. is wrong, I invalidate the field so I can put error messages besides the normal validation ones wherever

Any chance to get the ID of a new created record BEFORE I save it to the DB?

2009-12-02 Thread DigitalDude
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

Re: Any chance to get the ID of a new created record BEFORE I save it to the DB?

2009-12-02 Thread Dave
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 e.blumsten...@googlemail.comwrote:

Re: Any chance to get the ID of a new created record BEFORE I save it to the DB?

2009-12-02 Thread Miles J
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 davidcr...@gmail.com wrote: I think this would really help your situation

Re: Any chance to get the ID of a new created record BEFORE I save it to the DB?

2009-12-02 Thread Quess
@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