the queries generated in 0.3.6 and 0.3.8 are identical except for an  
anonymous alias name.  they are also both incorrect, and its only  
because 0.3.6 is less accurate about targeting Column objects in  
result sets that it "works".  the "task_id" column which youve  
labeled inside of "jj" does not appear due to a column targeting bug  
that is present in all versions, resolved in changeset 2708.  0.3.6  
just grabs the same column twice which is wrong as well.

the mapper in your example considers the primary key of "cls" to be  
the composite of task.id and the task_id "label" youve defined inside  
of "jj":

illustration of the primary key:

cls.mapper = mapper( cls, jjj, properties=props)
cls.mapper.compile()
print cls.mapper.primary_key

OrderedSet([Column('id',Integer(),primary_key=True,nullable=False),  
Column('task_id',Integer(),primary_key=True,nullable=False)])

which you probably should define as:

cls.mapper = mapper( cls, jjj, properties=props, primary_key= 
[jjj.c.task_id])

the bug also prevented the primary_key setting above from compiling  
properly in the mapper.

also, heres an alternate mapping to avoid the ambiguity presented by  
mapping to a join:

j  = outerjoin( task_t, message_t, task_t.c.id==message_t.c.task_id)
jj = select([ task_t.c.id.label('task_id'), func.count 
(message_t.c.id).label('props_cnt')],
               from_obj=[j], group_by=[task_t.c.id])

jjj = join(task_t, jj, task_t.c.id == jj.c.joined_task_id).select 
().alias('hi')

mapper(cls, jjj, primary_key=[jjj.c.task_id])



On Jun 6, 2007, at 3:55 PM, Dmitry Zuikov wrote:

>
>> once all that is done, then ill have a better idea of what youre
>> actually trying to do (if it doesnt actually fix the problem).
>
> Okay, I have posted the cleaned code above (or here http:// 
> dzuikov2.firstvds.ru/qqq.py).
> There are some comments about it.
>
> What I am trying to do? The simple thing: I have some related tables
> with mappers and I need the query wich shows some statistics (group
> functions involved). So I created a new mapper against the query.
> That's all. The query and the mapper work ok in 0.3.6 - you may run
> this code to check it out. In 0.3.8 it works with properties and
> relations but without offset/limit, or with offset/limit,  but without
> properties.  The query seems correct - it runs  without mapper.
>
> I do not use clear_mapper or even clear_mappers in real code.
>
>
> >


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