On Oct 17, 2013, at 6:34 AM, Victor Varvariuc <victor.varvar...@gmail.com> 
wrote:

> I have a model:
> 
> class ExchangeRate(Base):
>     ...
>     created_at = Column(DateTime, nullable=False, server_default=func.now())
>     updated_at = Column(DateTime, nullable=False, server_default=func.now(),
>                         server_onupdate=func.now())
> 
> Model fields `created_at` and `updated_at` have values generated by server, 
> but the value is not fetched automatically:
> 
>      14         with Session() as session:
> ---> 15             return session.merge(exchange_rate)
>      16 
> 
> ipdb> exchange_rate
> ExchangeRate(currency_from='RUB', currency_to='KZT', rate=Decimal('4.77'), 
> rounding_type='FLOOR', rounding_precision=-2)
> ipdb> session.merge(exchange_rate)
> ExchangeRate(currency_from='RUB', currency_to='KZT', rate=Decimal('4.77'), 
> rounding_type='FLOOR', rounding_precision=-2)
> ipdb> 
> 
> Do I do use it correctly?

if the question is, why don't you see created_at, updated_at, those would go in 
when the object is flushed, and then you'd only see them on the instance if you 
access them first, as server-generated defaults aren't automatically fetched 
back during flush (an improved "eager_defaults" feature in 0.9 makes this 
feasible, however: 
http://docs.sqlalchemy.org/en/latest/changelog/migration_09.html#orm-can-efficiently-fetch-just-generated-insert-update-defaults-using-returning).




> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/groups/opt_out.

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to