Hali!
Mi a legegyszerűbb módja annak, hogy egy pl. note = Notes.create(…)
után megkapjam az adott note ActiveRecord id-ját (primary key)? Sajnos
ez ugye 0, mivel frissen lett létrehozva…
Ã?tlet?
Gábor
Hali!
Mi a legegyszerűbb módja annak, hogy egy pl. note = Notes.create(…)
után megkapjam az adott note ActiveRecord id-ját (primary key)? Sajnos
ez ugye 0, mivel frissen lett létrehozva…
Ã?tlet?
Gábor
Hali!
Mi a legegyszerűbb módja annak, hogy egy pl. note = Notes.create(…)
után megkapjam az adott note ActiveRecord id-ját (primary key)? Sajnos
ez ugye 0, mivel frissen lett létrehozva…
Sorry, missed the proper mailing list
So how can I determine a newly created record’s primary key (id) after
issuing create method? Consider I have the following: note =
Notes.create(…). It will create a Notes record but note.id will be
zero instead of having valid primary key.
I know this is normal in term of RoR but is there an easy way to
retrieve the id of this object? Do I have to find the record again to
have its primary key?
Thanks,
Gábor
Gábor Sebestyén wrote:
So how can I determine a newly created record’s primary key (id) after
issuing create method? Consider I have the following: note =
Notes.create(…).
ActiveRecord’s create method instantly saves the record, the object
returned should have a valid id.
Perhaps the validation fails that’s why you are getting the unsaved
object with the id value nil.
Eszter
On 2/21/06, Gábor Sebestyén [email protected] wrote:
zero instead of having valid primary key.
I know this is normal in term of RoR but is there an easy way to
retrieve the id of this object? Do I have to find the record again to
have its primary key?
As Biro said, Note.create should include the correct id.
Make sure you’re passing enough data to pass the validations, though.
To make sure, try Note.create! instead of Note.create. That will
throw an Exception if the created object couldn’t be saved.
No luck. Object saves but it’s id remain zero (0). I can see the
created record in the database with valid primary key (pk = 24,
note.id = 0).
I use the latest rails distribution with sqlite3 for testing purposes.
Any hint?
Gábor
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs