Your dictionary key CartItemTable.c.colname is an instance of class
Column, The dictionary keys need to be strings. Use str
(CartItemTable.c.colname) to get the string name of the column and it
should work.

>>> CartItemTable.c.userId
Column('userId', Integer(), ForeignKey('User.userId'),
table=<CartItem>, primary_key=True, nullable=False)
>>> str(CartItemTable.c.userId)
'CartItem.userId'

--
Mike


On Nov 23, 8:12 am, "Petr Kobalíček" <[EMAIL PROTECTED]> wrote:
> Hi devs,
>
> I don't understand one thing:
>
> I have table:
>
> CartItemTable = sql.Table(
>   "CartItem", meta.metadata,
>
>   # Relations
>   sql.Column("userId"              , sql.Integer      ,
> sql.ForeignKey("User.userId"), nullable=False, primary_key=True),
>   sql.Column("productId"           , sql.Integer      ,
> sql.ForeignKey("Product.productId"), nullable=False,
> primary_key=True),
>   sql.Column("variantId"           , sql.Integer      , nullable=True,
> default=None),
>
>   # Count of items in shopping cart
>   sql.Column("count"               , sql.Integer      ,
> nullable=False, default=1)
> )
>
> and I want to insert multiple rows to it using sql:
>
>       Session().execute(
>         CartItemTable.insert(),
>         [{
>           CartItemTable.c.userId    : self.user.userId,
>           CartItemTable.c.productId : item.product.productId,
>           CartItemTable.c.variantId : vid(item.variant),
>           CartItemTable.c.count     : item.count
>         } for item in self.items]
>       )
>
> But this not works and I must use this way:
>
>       Session().execute(
>         CartItemTable.insert(),
>         [{
>           "userId"    : self.user.userId,
>           "productId" : item.product.productId,
>           "variantId" : vid(item.variant),
>           "count"     : item.count
>         } for item in self.items]
>       )
>
> Why is not working first syntax, what em I missing ?
>
> Cheers
> - Petr
--~--~---------~--~----~------------~-------~--~----~
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