Michael Bayer ha scritto: > On Apr 3, 2007, at 5:58 AM, Glauco wrote: > > >> In [1]: t = TipoFigura() >> >> In [1]: t.mapper.mapped_table >> Table('tipo_figura',DynamicMetaData(), >> Column('codice',PGChar(length=1),primary_key=True,nullable=False), >> Column('descrizione',PGText >> (length=None),nullable=False),schema=None) >> >> >> In [2]: s = select( [t.c.codice], from_obj=[t.mapper.mapped_table], >> use_labels=True) >> >> In [3]: ret = session.query( t.mapper ) >> >> In [4]: ret.instances( s.execute() ) >> 2007-04-03 11:27:26,575 sqlalchemy.engine.base.Engine.0x..74 INFO >> SELECT tipo_figura.codice AS tipo_figura_codice >> FROM tipo_figura >> >> >> /home/xxxx/build/bdist.linux-i686/egg/sqlalchemy/engine/base.py in >> _convert_key(self, key) >> NoSuchColumnError: "Could not locate column in row for column >> 'tipo_figura.descrizione'" >> >> >> >> 1) Why this error?? the query is perfect and there is n reason >> for check presence of the "descrizione" column. (the problem is >> the same i found in previous mail) >> > > the "descrizone" column is part of your mapping so the mapper will be > searching for it. understand that session.query() is *always* going > to load instances of the primary class - your "codice" column is in > *addition* to the main mapped class (but in this case, its already > part of it). > > if you just want to select "codice" alone with no mapped objects, > execute the select() statement by itself without using the ORM (i.e. > session.query). >
Yes, but i lost generative methods filter_by > >> 2) and why if i put all columns i lost use_label features ? >> >> s = select( [t.c.codice, t.c.descrizione], from_obj= >> [t.mapper.mapped_table], use_labels=True) >> >> ret.instances( s.execute() )[0].c.keys() >> >> 2007-04-03 11:39:56,921 sqlalchemy.engine.base.Engine.0x..74 INFO >> SELECT tipo_figura.codice AS tipo_figura_codice, >> tipo_figura.descrizione AS tipo_figura_descrizione >> FROM tipo_figura >> 2007-04-03 11:39:56,921 sqlalchemy.engine.base.Engine.0x..74 INFO {} >> >> Out[15]: ['codice', 'descrizione'] >> >> > > the "instances" method does not return result rows - it returns > object instances. the "c" attribute there is off of one of your > mapped classes and the two column names are the columns off of your > original Table object. > > to get the columns you want > > s = select( [t.c.codice, t.c.descrizione], from_obj= > [t.mapper.mapped_table], use_labels=True).execute()[0].keys() > Yes in fact this is only an example.. my purpose is to implement this system for do generic search function over complex mapper , for example my first work is a mapper over 19 tables with 1 relation n:m and 2 1:n...... i need some features from select function and other from generative qry over mapper... but it's difficult to concentrate all cases in one select function. Glauco -- +------------------------------------------------------------+ Glauco Uri - Programmatore glauco(at)allevatori.com Sfera Carta Software® [EMAIL PROTECTED] Via Bazzanese,69 Casalecchio di Reno(BO) - Tel. 051591054 +------------------------------------------------------------+ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---