[sqlalchemy] Re: Column metadata from mapped class

2008-07-22 Thread Sean Davis



On Jul 20, 11:28 am, Michael Bayer [EMAIL PROTECTED] wrote:
 On Jul 20, 2008, at 7:48 AM, Sean Davis wrote:



  I have been playing with 0.5 and have a very simple question.  If I
  have a mapped class, User, how can I get at the columns of User?  I
  see lots of constructs like User.c, but User has no 'c' attribute
  now.  I am looking at finding the column types, names (to loop over),
  etc.

 theres a large section regarding this in the upgrade notes 
 athttp://www.sqlalchemy.org/trac/wiki/05Migration
 , though its focused on rationale .   The short answer for columns is  
 to use the Table (i.e. sometable.c.somecolumn, for col in  
 sometable.c:, etc).   If you want to get the table for a mapped class  
 if you don't have it already, say class_mapper(cls).mapped_table.

Thanks, and sorry I didn't look at that doc before asking.  That is
exactly what I needed.

Sean

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Column metadata from mapped class

2008-07-22 Thread huy do



On Jul 22, 1:33 pm, Michael Bayer [EMAIL PROTECTED] wrote:
 On Jul 21, 2008, at 9:45 PM, huy do wrote:



  Because a mapped class can have an arbitary select as it's source i.e
  columns from any table theoretically, it would still be nice to know
  exactly which columns were used to map the properties of a given
  class. The .c on the model class use to give us the metadata (i.e
  either the select or table aka relation) which was used to populate
  the class. Can we get an extension to get this feature back (please) ?

 If you just want the Table, its just  
 class_mapper(class).mapped_table.    Theres lots of ways to build your  
 own .c. class attirbute and such, including:

         MyClass.c = class_mapper(MyClass).columns

cool.


 the .c. really had to be removedits entirely different now if  
 you say query.filter(MyClass.c.foo=='bar') in 0.5 since no adaptation  
 will take place.

I don't mind getting rid of  MyClass.c.foo == 'bar' with MyClass.foo
== 'bar',
but is it possible to add MyClass.foo.c to get at the metadata behind
the column itself.

Thanks

huy

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Column metadata from mapped class

2008-07-22 Thread Michael Bayer



On Jul 22, 8:04 am, huy do [EMAIL PROTECTED] wrote:
 On Jul 22, 1:33 pm, Michael Bayer [EMAIL PROTECTED] wrote:



  On Jul 21, 2008, at 9:45 PM, huy do wrote:

   Because a mapped class can have an arbitary select as it's source i.e
   columns from any table theoretically, it would still be nice to know
   exactly which columns were used to map the properties of a given
   class. The .c on the model class use to give us the metadata (i.e
   either the select or table aka relation) which was used to populate
   the class. Can we get an extension to get this feature back (please) ?

  If you just want the Table, its just  
  class_mapper(class).mapped_table.    Theres lots of ways to build your  
  own .c. class attirbute and such, including:

          MyClass.c = class_mapper(MyClass).columns

 cool.



  the .c. really had to be removedits entirely different now if  
  you say query.filter(MyClass.c.foo=='bar') in 0.5 since no adaptation  
  will take place.

 I don't mind getting rid of  MyClass.c.foo == 'bar' with MyClass.foo
 == 'bar',
 but is it possible to add MyClass.foo.c to get at the metadata behind
 the column itself.

 Thanks

 huy

that you have, MyClass.foo.property.columns.  its a list since
multiple cols can be associated with one attribute.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Column metadata from mapped class

2008-07-21 Thread Michael Bayer


On Jul 21, 2008, at 9:45 PM, huy do wrote:


 Because a mapped class can have an arbitary select as it's source i.e
 columns from any table theoretically, it would still be nice to know
 exactly which columns were used to map the properties of a given
 class. The .c on the model class use to give us the metadata (i.e
 either the select or table aka relation) which was used to populate
 the class. Can we get an extension to get this feature back (please) ?


If you just want the Table, its just  
class_mapper(class).mapped_table.Theres lots of ways to build your  
own .c. class attirbute and such, including:

MyClass.c = class_mapper(MyClass).columns

the .c. really had to be removedits entirely different now if  
you say query.filter(MyClass.c.foo=='bar') in 0.5 since no adaptation  
will take place.




--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Column metadata from mapped class

2008-07-20 Thread Michael Bayer


On Jul 20, 2008, at 7:48 AM, Sean Davis wrote:


 I have been playing with 0.5 and have a very simple question.  If I
 have a mapped class, User, how can I get at the columns of User?  I
 see lots of constructs like User.c, but User has no 'c' attribute
 now.  I am looking at finding the column types, names (to loop over),
 etc.


theres a large section regarding this in the upgrade notes at 
http://www.sqlalchemy.org/trac/wiki/05Migration 
, though its focused on rationale .   The short answer for columns is  
to use the Table (i.e. sometable.c.somecolumn, for col in  
sometable.c:, etc).   If you want to get the table for a mapped class  
if you don't have it already, say class_mapper(cls).mapped_table.


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---