On Feb 7, 2011, at 10:55 AM, Martijn Moeling wrote: > Hi, > > It is me again with an interesting thing, I've searched the net, this group > etc. Not a lot of people seem interested in append_result, I AM!! > > I am looking for a way to implement the following: > > > I have many tables, a lot with polymorphic inheritance and self and cross > references. > > In order to control "available" data I have set up a system similar to ACL > (Access Control Lists) > > Depending on "Who I am" I can get data from the database. > > I want to do so within the MapperExtension I already have set up to do some > "before update" and "before insert"
Limitations on inserts, updates and queries are best done outside of the Mapper. By the time the mapper is dealing with instructions to persist or load a row, its usually too late, unless you're looking to raise an exception upon certain conditions. For example there's no way to "stop" the insert from happening inside of a "before insert" operation, short of raising an exception (maybe that's what you're doing). A SessionExtension.before_flush() OTOH allows you to modify everything that's going to happen before any flush plans are made. Regarding append_result(), its a very old hook from 0.1 that's never had any real use. In this case I would instead be ensure that the undesired rows are not in the result set to start with. The recipe at http://www.sqlalchemy.org/trac/wiki/UsageRecipes/PreFilteredQuery is a decent starting point for such a recipe. > > > def append_result(self, mapper, selectcontext, row, instance, result, > **flags): > if instance.__tablename__ == 'he': > return EXT_STOP > else: > return EXT_CONTINUE > > would do such a thing, but I want (for the sake of the code behind that) to > continue with a heavily modified instance. > > To avoid making this long code (a lot of different object types pass through > here, remember the polymorhic bit) > > Does anyone have an interesting approach to this? basically I need to do > something like instance= instance_class_type(new, configuration, based, on, > the, ACL) > > > > Any help would be wonderfull, > > Martijn > > > > > > > > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to [email protected]. > 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. > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to [email protected]. 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.
