[EMAIL PROTECTED] wrote:
> Hi all,
>
> i have the following scenario for a real-estate search engine:
>
> "Ad" table where i define the properties of the ad such as created_on,
> expires_on, user_id and is related with a 1-1 FK to the "Property"
> table which defines stuff such as sq_feet, district_id etc...
>
> I'd like to keep them separated (though your design advice is more than
> welcome) but how do i make sure to populate the Ad table with the
> correct property_id which has just been added to the Property table?
> The "Get Latest Object" recipe is not safe to use here. Still, if i
> wrap everything in a transaction i need to get the property_id just
> created.
>
> With SqlServer i would return the @@Identity and use it to populate the
> property_id FK on the Ad table... i need something like that.
>
> Hope i expressed my thoughts clearly ;-)
>
> Thanks,
> Lorenzo

The identity value is set in the new instance once you call save so you
can simply do this:

    p = Property(sq_feet=2300, ...)
    p.save()  # now p.id is set

    a = Ad(property=p, ...)
    a.save()

The equivalent of the @@Identity trick is handled during 'save' via the
db backend's get_last_insert_id function which is database-dependent.
-Dave


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to