Using 0.5.0rc4 doesn't seem to do that. or what am I doing wrong?

The test, http://pastebin.com/fd0653b0 , looks like when using the
Column object, the values inserted are all None (test 1). When the key
is the fully qualified "table.column", the value inserted is always
the default value for the column (test 3). It only works correct when
the key is the string for the unqualified column name (tests 2 and 4).


On Nov 24, 10:37 am, "Michael Bayer" <[EMAIL PROTECTED]> wrote:
> the actual Column object or its "key" can be placed in the dict.
>
> MikeCo wrote:
>
> > Oops, not quite right. str(table.c.colname) returns 'table.colname",
> > and that doesn't work right as dictionary key. You need "col" only as
> > dictionary key.
>
> >http://pastebin.com/fd0653b0 has some tests
>
> > Interesting question is does SA intend that "table.colname" work in
> > the dictionary definition?
>
> > --
> > Mike
>
> > On Nov 23, 8:58 am, MikeCo <[EMAIL PROTECTED]> wrote:
> >> 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 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