Jamie Bullock wrote:
>
>
> Hi,
>
> Is there a way in SQLalchemy to have the values of a mapped reflected
> table object set to default column values derived from the database
> backend?
>
> e.g.  if column 'bar' of table 'foo' in my database has a default of
> "True", I would like to be able to do the following:
>
>>>> foo_table = Table("foo", metadata, autoload=True,
>>>> autoload_with=engine)
>>>> mapper(Foo, foo_table)
>>>> f = Foo()
>>>> f.bar
> True
>
> Instead f.bar is None.
>
> Is there an elegant way to achieve this without querying
> information_schema and setting the defaults from there?

what's "elegant" to me is:

>>> f = Foo()
>>> Session.add(f)
>>> Session.flush() # or commit
>>> f.bar
True

consider that Foo() wouldn't know about server generated defaults if not
associated with the database.  The database association is achieved using
Session.add().


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
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