> On Oct 22, 2014, at 2:34 PM, Pedro Werneck <pjwern...@gmail.com> wrote:
> 
>> On Wed, Oct 22, 2014 at 3:27 PM, Michael Bayer <mike...@zzzcomputing.com> 
>> wrote:
>> 
>> why not try something like:
>> 
>> ualias = aliased(User, table_2012)
>> 
>> query(ualias).filter(ualias.x == 1)
> 
> I tried that before, but I always end up with a query to the two
> tables, and the filtering applied to the User table:

Yeah, that's because the alternate tables have no correspondence to the 
original one, the way a SELECT would.    So without building some new kind of 
core selectable that acts this way, these approaches won't work here.

Based on your case that you do want a UNION that populates a collection that is 
entirely straight User objects, that does imply these would be concrete 
inheriting subclasses.  




> 
>>>> u1 = aliased(User, user_1)
>>>> print db.session.query(u1).filter(u1.username=='lero')
> SELECT user_active.user_id AS user_active_user_id,
> user_active.username AS user_active_username
> FROM user_active, user_1
> WHERE user_active.username = :username_1
> 
> If I try aliased with adapt_on_names=True it gets reversed:
> 
>>>> u1 = aliased(User, user_1, adapt_on_names=True)
>>>> print db.session.query(u1).filter(u1.username=='lero')
> SELECT user_active.user_id AS user_active_user_id,
> user_active.username AS user_active_username
> FROM user_active, user_1
> WHERE user_1.username = :username_1
> 
> The WHERE clause is correct, but it's still selecting from
> user_active, not user_1, so I exactly the results I don't want. If I
> could get it to select from user_1, I could get that to work by making
> the user_active part an empty result set.
> 
>> query(User).select_from(table_2012)
>> 
>> something like that.
> 
> That was the first thing I tried before the non_primary mapper thing.
> It has the same problem:
> 
>>>> print 
>>>> db.session.query(User).select_from(user_1).filter(User.username=='pedro')
> SELECT user_active.user_id AS user_active_user_id,
> user_active.username AS user_active_username
> FROM user_active, user_1
> WHERE user_active.username = :username_1
> 
> 
> 
>> it can’t be 100% transparent, the query needs to be told that its selecting 
>> from something different.
> 
> This inner implementation doesn't really need to be 100% transparent,
> as long as it gets correct results.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to