[sqlalchemy] How to automatically handle deletion flags

2014-02-27 Thread RonnyPfannschmidt
Hi, im working on a project where in many tables data can not be deleted, but only marked as deactivated, Propperly handling selection of active data for normal users and all data for admins is turning more and more tendious (in particular wrt relationship configuration) Im wondering if there

Re: [sqlalchemy] How to automatically handle deletion flags

2014-02-27 Thread Simon King
On Thu, Feb 27, 2014 at 8:44 AM, RonnyPfannschmidt ronny.pfannschm...@gmail.com wrote: Hi, im working on a project where in many tables data can not be deleted, but only marked as deactivated, Propperly handling selection of active data for normal users and all data for admins is turning

Re: [sqlalchemy] How to automatically handle deletion flags

2014-02-27 Thread RonnyPfannschmidt
im already aware of that, but it doesnt expand to relationships and other things basically i need it taken into account in a lot more places On Thursday, February 27, 2014 10:59:21 AM UTC+1, Simon King wrote: On Thu, Feb 27, 2014 at 8:44 AM, RonnyPfannschmidt ronny.pfa...@gmail.com

Re: [sqlalchemy] How to automatically handle deletion flags

2014-02-27 Thread Simon King
That wiki page also links to: https://bitbucket.org/zzzeek/sqlalchemy/wiki/UsageRecipes/GlobalFilter which is intended to work with relationships as well, but it seems a lot more complicated. Another option might be to map to a SELECT, rather than directly to a table.

Re: [sqlalchemy] How to automatically handle deletion flags

2014-02-27 Thread Michael Bayer
Also in the relationship docs, see relationship to non primary mapper, which illustrates how to make ad-hoc relationships to subqueries, though typically relationship to target where deleted=false is just a custom primary join condition, a subquery is probably not needed here. Sent from my

Re: [sqlalchemy] How to automatically handle deletion flags

2014-02-27 Thread RonnyPfannschmidt
the problem is that it shouldn't just be taken into account for relationships but all queries that operate on such a table with the flag On Thursday, February 27, 2014 3:22:29 PM UTC+1, Michael Bayer wrote: Also in the relationship docs, see relationship to non primary mapper, which

[sqlalchemy] How to confirm if dogpile caching is working

2014-02-27 Thread gupta . sandeep
I just checked out the examples for using dogpile caching mentioned here: http://docs.sqlalchemy.org/en/rel_0_9/orm/examples.html#module-examples.dogpile_caching. According to the example in helloworld.py if a query is cached i.e. run the second time then the SQL is not generated. To

[sqlalchemy] How to order a many-to-many association_proxy?

2014-02-27 Thread Seth P
Apologies if I'm missing this is the docs somewhere, but I can't figure it out. Suppose I have a many-to-many relationship between A and B, and that I'd like have the various B's that a particular A points to ordered by B.ordinal (i.e. in the examples below, I'd like A.bs to be sorted to

[sqlalchemy] Re: How to order a many-to-many association_proxy?

2014-02-27 Thread Seth P
Just noticed that I had a typo, where I wrote order_by=b.ordinal rather than order_by=b.order. But changing it to order_by=b.order still gives: AttributeError: 'RelationshipProperty' object has no attribute 'order' -- You received this message because you are subscribed to the Google Groups

[sqlalchemy] How to order many-to-many association_proxy?

2014-02-27 Thread Seth P
How do I get the objects pointed to by a many-to-many association proxy to be sorted? In the example below, adding order_by=b.order to the backref() produces AttributeError: 'RelationshipProperty' object has no attribute 'order', and adding order_by=b.order produces AttributeError: 'Table'

[sqlalchemy] Trouble filtering binary columns with tuple_ and an in_ clause against Postgres

2014-02-27 Thread Rob Crowell
When I pass binary data to a multi-column in_ clause, I seem to be geting inconsistent results and I need some help! I did some testing with MySQL, Postgres, and Vertica (connecting via https://pypi.python.org/pypi/vertica-sqlalchemy/0.1). It appears MySQL works correctly but both Postgres

Re: [sqlalchemy] How to confirm if dogpile caching is working

2014-02-27 Thread Michael Bayer
this is what the output should look like, after all the INSERT statements: loading people 2014-02-27 18:49:25,502 INFO sqlalchemy.engine.base.Engine BEGIN (implicit) 2014-02-27 18:49:25,503 INFO sqlalchemy.engine.base.Engine SELECT person.id AS person_id, person.name AS person_name FROM

Re: [sqlalchemy] How to order a many-to-many association_proxy?

2014-02-27 Thread Michael Bayer
Since this is the association object pattern, I’ll describe that first. The pattern there is a little complicated, but if you can go with a straight many-to-many, it is then much easier. The relationship as specified here is from A to A_to_B. If I have an “A” row loaded into some_a, and

Re: [sqlalchemy] Trouble filtering binary columns with tuple_ and an in_ clause against Postgres

2014-02-27 Thread Michael Bayer
On Feb 27, 2014, at 4:38 PM, Rob Crowell rob.crow...@moat.com wrote: # in_ clause with 1 STRING, 1 BINARY filter_cols = tuple_(HashTest.hash_val, HashTest.hash_type) filter_vals = ((encoded_hash, 'md5'),) q = session.query(HashTest) q =

Re: [sqlalchemy] Trouble filtering binary columns with tuple_ and an in_ clause against Postgres

2014-02-27 Thread Michael Bayer
that patch is in for 0.8 and 0.9. On Feb 27, 2014, at 7:29 PM, Michael Bayer mike...@zzzcomputing.com wrote: On Feb 27, 2014, at 4:38 PM, Rob Crowell rob.crow...@moat.com wrote: # in_ clause with 1 STRING, 1 BINARY filter_cols = tuple_(HashTest.hash_val, HashTest.hash_type)

Re: [sqlalchemy] How to automatically handle deletion flags

2014-02-27 Thread Michael Bayer
you have to roll it yourself. query subclass + relationship + whatever else. On Feb 27, 2014, at 10:35 AM, RonnyPfannschmidt ronny.pfannschm...@gmail.com wrote: the problem is that it shouldn't just be taken into account for relationships but all queries that operate on such a table with

Re: [sqlalchemy] How to automatically handle deletion flags

2014-02-27 Thread Michael Bayer
or, if you totally just map that class to a SELECT statement that includes the criterion, that will do it too. but then you’ll get a lot of SELECT subqueries you might not want. or, create a view using CREATE VIEW. then map to that. That is definitely the most simple and SQL efficient way

Re: [sqlalchemy] How to order a many-to-many association_proxy?

2014-02-27 Thread Seth P
Thank you. This was very helpful. One non-trivial thing that stumped me for a while is that if B is derived from a B_base using joined-table inheritance, and the order variable is in the base table B_base, then it seems one must include B_base explicitly -- as highlighted below. from

Re: [sqlalchemy] How to order a many-to-many association_proxy?

2014-02-27 Thread Michael Bayer
On Feb 27, 2014, at 9:23 PM, Seth P spadow...@gmail.com wrote: Thank you. This was very helpful. One non-trivial thing that stumped me for a while is that if B is derived from a B_base using joined-table inheritance, and the order variable is in the base table B_base, then it seems one

Re: [sqlalchemy] How to order a many-to-many association_proxy?

2014-02-27 Thread Seth P
Good point, but unfortunately, unless I'm missing something, including only B_base and removing B from the join doesn't seem to work when A is also derived (using joined-table inheritance) from B_base (which is my actual situation, despite what the nomenclature here suggest). On Thursday,