the typical hooks are: Query subclass, @compiles on select(), or a connection or cursor execute event.
On Feb 28, 2014, at 11:01 AM, RonnyPfannschmidt <ronny.pfannschm...@gmail.com> wrote: > is there any general hook that allows to access a query before it is compiled > and executed > im wondering about attaching criterion's to all joins and tables that will > need it > > On Friday, February 28, 2014 3:10:56 AM UTC+1, Michael Bayer wrote: > 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 to do it. depends on how much > flexibility you need. > > > On Feb 27, 2014, at 10:35 AM, RonnyPfannschmidt <ronny.pfa...@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 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 >> 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 iPhone >> >> > On Feb 27, 2014, at 8:25 AM, Simon King <si...@simonking.org.uk> wrote: >> > >> > 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. >> > >> > >> > http://docs.sqlalchemy.org/en/rel_0_9/orm/mapper_config.html#mapping-a-class-against-arbitrary-selects >> > >> > >> > The docs discourage mapping to a select because of the complexity of >> > the resulting queries, but in your case perhaps those queries are >> > exactly what is required. >> > >> > Hope that helps, >> > >> > Simon >> > >> > On Thu, Feb 27, 2014 at 1:06 PM, RonnyPfannschmidt >> > <ronny.pfa...@gmail.com> wrote: >> >> >> >> 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> 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 more and more tendious (in particular wrt >> >>>> relationship >> >>>> configuration) >> >>>> >> >>>> Im wondering if there is a way to configure mappers/queries to >> >>>> automatically >> >>>> take such flags into account. >> >>>> >> >>>> -- Ronny >> >>> >> >>> Perhaps something like this might help: >> >>> >> >>> >> >>> https://bitbucket.org/zzzeek/sqlalchemy/wiki/UsageRecipes/PreFilteredQuery >> >>> >> >>> >> >>> Simon >> >> >> >> -- >> >> 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+...@googlegroups.com. >> >> To post to this group, send email to sqlal...@googlegroups.com. >> >> Visit this group at http://groups.google.com/group/sqlalchemy. >> >> For more options, visit https://groups.google.com/groups/opt_out. >> > >> > -- >> > 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+...@googlegroups.com. >> > To post to this group, send email to sqlal...@googlegroups.com. >> > Visit this group at http://groups.google.com/group/sqlalchemy. >> > For more options, visit https://groups.google.com/groups/opt_out. >> >> -- >> 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+...@googlegroups.com. >> To post to this group, send email to sqlal...@googlegroups.com. >> Visit this group at http://groups.google.com/group/sqlalchemy. >> For more options, visit https://groups.google.com/groups/opt_out. > > > -- > 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/groups/opt_out.
signature.asc
Description: Message signed with OpenPGP using GPGMail