we currently have this feature:

http://www.sqlalchemy.org/docs/adv_datamapping.myt#advdatamapping_selects

which can return a result with more than one entity per row.  the hard
part here is defining the select statement.  SQLAlchemy doesnt know
how to compile select statements that go across multiple entities (its
a method called Query.compile()).

Id rather not shove an "add an extra class" option into our existing
Query.compile() method.  if Query is going to work for multiple
classes at once, then id want to at least consider building it that
way from the ground up.  youd say
session.query().add_entity(SomeEntity).add_entity(SomeOtherEntity).add_criterion(etc).
(although yes, that is too verbose).

as ive been considering what the next generation of Query will look
like for version 0.4 (or maybe 0.5, dunno), ill take it under
consideration that some people actually do want Hibernate's "load any
number of entities at once, without writing SELECT statements"
approach.


On Mar 8, 3:59 am, Glauco <[EMAIL PROTECTED]> wrote:
> Michael Bayer ha scritto:> SelectResults is used for mapped classes, the 
> columns that are to be
> > selected for a particular mapping are fixed.  theres no reason youd
> > want to be able to change the column clause.
>
> I try to do an example:
>
> create table macrocategory ( code char(3),
>                              description text );
> create table subcategory ( code char(3),
>                            description text,
>                            cod_macrocategory char(3) reference
> macrocategory(code) );
> create table category ( code char(3),
>                         description text,
>                         cod_subcategory char(3) reference
> subcategory(code) );
>
> This is my example_mapper.py
>
> class _Subcategory(DomainObject, SferaDomainObject):
>     def __str__(self):
>         return self.code
>
> assign_mapper(context,
>               _Subcategory,
>               tbl['subcategory'],
>               column_prefix = 'subcategory_'
>               extension = SelectResultsExt()
>               properties = {'category'  : relation( _category ),
> )
>
> class _Category(DomainObject, SferaDomainObject):
>     def __str__(self):
>         return self.code
>
> assign_mapper(context,
>               _Category,
>               tbl['category '],
>               extension = SelectResultsExt()
>               column_prefix = 'category_',
> )
>
> class Macrocategory(DomainObject, SferaDomainObject):
>     def __str__(self):
>         return self.code
>
> def search( self, **kw  ):
>         """
>         Generic Search function
>         """
>         by_where_clause = {}
>         where_clause = []
>         for k,v in kw.items():
>             if k in ('macrocategory_',\
>                      'subcategory_code',\
>                      'subcategory_description',\
>                      'subcategory_cod_macrocategory',\
>                      'category_code',\
>                      'category_description',\
>                      'category_cod_subcategory'):
>                  by_where_clause[ k ] = v
>
>             elif k == 'macrocategory_description':
>                 where_clause.append(
> self.c.macrocategory_description.op('ilike')('%'+v+'%')
>
>             else:
>                 raise ValueError, "Unknow search parameter"
>
>         if where_clause:
>            return self.select_by( **by_where_clause ).select( and_(
> *where_clause )
>         else:
>            return self.select_by( **by_where_clause )
>
> assign_mapper(context,
>               Macrocategory,
>               tbl['macrocategory '],
>               extension = SelectResultsExt()
>               column_prefix = 'macrocategory_',
> )
>
> Why  i do that?
>
> My primary purpose is to get from mappers the correct reference
> "from-to" table and have the simplest select qry using select_by function.
> Obviously the search function  was the unique select function over these
> 3 tables and i must pass some parameters to it for retrieving some field
> or other fields.
>
> If i pass a first level table field the select_by do correclty a
> select from macrocategory
>
> If i pass a second level table field the select_by do correclty a
> select from macrocategory join subcategory
>
> and so on for  select from macrocategory join subcategory join category
>
> The where_clause was compiled correclty, *BUT* in this structure the SA
> get always all field only from first mapper and sometimes i want field
> from all three mapper so all programmes mus do search traversing this 3
> mappers mus everytime build this own search function and finally i have
> a lot of redundat code like this.....
>
> select([filed, field, field],      from_obj=[
> Macrocategory.join(_Subcategory,
>
> Macrocategory.c.code == _Subcategory.c.cod_macrocategory
>                       ).join(_Category,  bla bla bla
>
> Try to imagine my case have over 10 tables whith a lot of condition for
> primary key and condition...
> my work for maintain this library in a pythonic form is enormous
>
> This problem is olny mine? i'm doing an incorrect use of SA ?
>
> Thank's
> Glauco
>
>
>
> > Hibernate does have the ability to stick arbitrary columns into
> > mapping queries which are returned as scalars.  im not sure if SA
> > needs this so much as we have the entire SQL construction facility
> > that can be used on its own (hibernate doesnt).
>
> > On Mar 7, 2007, at 4:02 AM, Glauco wrote:
>
> >> Glauco ha scritto:
>
> >> <CUT>
>
> >> The simplest example is to specify columns to select on a generated
> >> qry
> >> (not all field of all tables involved in the generated qry).
>
> >> does the  sqlalchemy.ext.selectresults.SelectResults object have
> >> something like "column clause" parameter of select function?
>
> >> Thank's
> >> Glauco
>
> >> --
> >> +------------------------------------------------------------+
> >>                                   Glauco Uri - Programmatore
> >>                                     glauco(at)allevatori.com
>
> >>   Sfera Carta Software®      [EMAIL PROTECTED]
> >>   Via Bazzanese,69  Casalecchio di Reno(BO) - Tel. 051591054
> >> +------------------------------------------------------------+
>
> --
> +------------------------------------------------------------+
>                                   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
-~----------~----~----~----~------~----~------~--~---

Reply via email to