since you need the relationship part also did you try a mapping to a
select() statement?    The downside of that would be that your queries
would always be like "SELECT ... FROM (SELECT .. FROM..)".     The
other way is to alter the query.   You can probably do pretty well on
this with a before_compile event:
http://docs.sqlalchemy.org/en/latest/orm/events.html?highlight=before_compile#sqlalchemy.orm.events.QueryEvents.before_compile
 shows pretty much exactly how you'd do this (e.g. look in the
entities for the one that has special filter criteria, then add that
criteria).

On Sat, Mar 17, 2018 at 7:47 PM, Jonathan Vanasco <jvana...@gmail.com> wrote:
> I was wondering if something were doable with SqlAlchemy in a decently
> performant manner that can be maintained cleanly.  I'm open to any
> strategies that people can suggest.
>
> We have a handful of reserved internal "system" or "control" records in our
> database. Depending on the table, anywhere from 10k to 1MM ids are reserved
> (in practice, only 10 are actually used).
>
> I'd like to exclude these items from showing up in relationships (and
> possibly even from appearing on a record as an id field).  They are only
> needed in our Admin interface (runs as a separate app, so it can be
> configured differently), but are a hindrance on the Public app.
>
> Here's a typical use case:
>
> One of our tables represents a content-graph of spidered web pages. During
> the course of development, we realized certain data wasn't being attributed
> to the right pages due to issues with redirect detection in a specific
> scenario.  Consequently, a chunk of records created before we addressed this
> case now list their 'redirected_from' id as the control record for
> "Untracked Redirect Chain".  (Due to the size of the DB and several other
> constraints, adding in a new field to track errors/data wasn't an option).
>
> That leaves me needing to hide this connection in two places on our
> clientside app:
> * don't load it into a sqlalchemy.orm.relationship
> * discard it when looking at the raw column ids (when populating the
> read-through cache)
>
> To handle this, I'm doing the latter manually and using a 'display_'
> prefixed property to wrap the real relationship - but this is ugly.
>
> I'm hoping for some suggestions from the larger community.
>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
> description.
> ---
> 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 https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to