> From: sqlalchemy@googlegroups.com [mailto:sqlalch...@googlegroups.com]
> On Behalf Of Michael Bayer
> 
> On Jan 5, 2009, at 3:49 PM, arn vollebregt wrote:
> 
> > But isn't the identity comprised of the object class and the primary
> > key?
> > Would that not make the Foo instances the same in the eyes of
> > SQLAlchemy? Or
> > am I perhaps confusing the id variable with the real primary key
> > which is
> > stored somewhere else?
> 
> it is.  but this identity is not assigned until after the INSERT
> occurs.

Ah, I understand now :)

> > Is this declarative approach the only option, or is that just what
> you
> > happen to prefer? I am trying to keep my database/SQLAlchemy 'layer'
> > separated from my object declarations in my code, hence the question.
> 
> its just using column_property() which is like anything else you send
> to mapper(... properties={}).  Just pull the column within from the
> mapped table.

Ah ok, there surfaces my lack of SQLAlchemy experience. Doesn't sounds too
hard, so should be able to figured that one out :)

> > Right, next stop for me is writing an add_or_merge() function which
> > tries to
> > add an object to the session, and returns an existing object when a
> > UniqueConstraintException is raised. Sounds like a challenge when
> > relations
> > and association_proxy's come into play :)
> 
> it does.  merge() doesn't have those kinds of hooks.  I'd consider
> using a creational pattern to return the unique object instead, i.e.
> such as a specialized __new__:
> 
> x = MyInstance(session, foo=1, bar=2)
> 
> class MyInstance(object):
>      def __new__(cls, session, foo, bar):
>          if <check the session for foo, bar>:
>              return <my unique map>[(foo, bar)]
>          else:
>              return object.__new__(cls)

That looks like a clean approach, I'll play around with that during the next
few days.

Thx again for helping me on my way like this! Nice to see the main developer
is this active on the mailing list, and it's very kind of you to be so
patience with new users like myself :)

Regards,

Arn Vollebregt


--~--~---------~--~----~------------~-------~--~----~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to