Anil wrote:
> On Sep 14, 7:36 am, Anil <[EMAIL PROTECTED]> wrote:
>> <class 'sqlalchemy.exceptions.FlushError'>: instance Location is an
>> unsaved, pending instance and is an orphan (is not attached to any
>> parent 'Host' instance via that classes' 'location' attribute, nor any
>> parent 'User' instance via that classes' 'location' attribute)
>>
>> I have three tables: Host, User and Location
>> Host and User have a Location as a relation using the 'location' attribute.
>>
>> In a specific piece of code, I wanted to just create a new Location
>> (which is not associated with any User or Host table), so I did:
>>
>> location = model.Location(ip.lat, ip.lon)
>> location.ip = ip_integer
>> location.address = ", ".join((ip.city, ip.country))
>> location.code = ip.code
>>
>> model.Session.save(location)
>> model.Session.commit()
>
> BTW, here are my mappers:
> mapper(User, user_table, properties = {
>                                           'location':
> relation(Location, cascade="all, delete-orphan")
>                                           })
> mapper(Host, host_table, properties = {
>                                        'notifications':
> relation(Notification, cascade="all, delete-orphan"),
>                                        'location': relation(Location,
> cascade="all, delete-orphan")
>                                        })
> mapper(Location, location_table)

With 'delete-orphan' you're asking that all unattached Locations be 
deleted.  Then with save(location) you're trying to store an unattached 
Location...



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

Reply via email to