Given the three mappings *First*, *Second* and *Partitioned*, I want to declare a relationship between *First* and *Partitioned*. The problem is that *Partitioned* is partitioned by partition_key which is a column in *First* but not in *Second*. *Second* however contains the identifier that actually links *First* to specific rows in the partitioned table.
So far the mapping looks like this mock example: partitioned = relationship("Partitioned", secondary=Base.metadata.tables['schema.seconds'], primaryjoin="and_(First.first_id==Second.first_id, First.partition_key==Partitioned.partition_key)", secondaryjoin="Second.other_id==Partitioned.other_id", foreign_keys="[Second.first_id, Partitioned.partition_key, Partitioned.other_id]", uselist=True, innerjoin=True, lazy='dynamic') It works, but it only interpolates the First.first_id with the actual value which normally makes sense but to make the PostgreSQL constraint-exclusion work the First.partition_key would need to be interpolated with the proper value as well. Right now it is only given as First.partition_key==Partitioned.partition_key. Does that make sense? I am not sure if my relationship configuration is wrong or if this kind of mapping is simply not supported. On Thu, Dec 5, 2013 at 3:31 PM, Michael Bayer <mike...@zzzcomputing.com>wrote: > > On Dec 5, 2013, at 6:57 AM, Adrian Schreyer <adrian.schre...@gmail.com> > wrote: > > Actually that was a bit too early but I tracked the problem down to the > many-to-many relationship. Parameters are only interpolated (e.g. > %(param_1)s) for the primaryjoin to the secondary table. Is there a > technique to force relationship() to interpolate a parameter between the > 1st and 3rd table instead of using only table.column=table.column? > > > there’s no reason why that would be the case can you provide more > specifics? > > > > > > > On Thu, Dec 5, 2013 at 10:58 AM, Adrian Schreyer < > adrian.schre...@gmail.com> wrote: > >> Never mind, >> >> the problem was that I specified the clause in a secondaryjoin and not in >> the primaryjoin of the relationship(). >> >> >> On Thu, Dec 5, 2013 at 10:44 AM, Adrian <adrian.schre...@gmail.com>wrote: >> >>> Hi All, >>> >>> I have a few partitioned tables in my PostgreSQL database but I do not >>> know yet how to make the ORM relationship() with partition >>> constraint-exclusion<http://www.postgresql.org/docs/9.3/static/ddl-partitioning.html#DDL-PARTITIONING-CONSTRAINT-EXCLUSION> >>> on >>> the instance level. Constraint-exclusion does not work with joins and >>> requires scalar values - the problem is that I would need to add an >>> additional WHERE clause to the primaryjoin (which adds the partition key) >>> if the relationship is accessed from the* instance level*, e.g. >>> user.addresses. Is there a mechanism in relationship() to distinguish >>> between class-based joins (User.addresses) and instance-level access? >>> >>> -- >>> You received this message because you are subscribed to a topic in the >>> Google Groups "sqlalchemy" group. >>> To unsubscribe from this topic, visit >>> https://groups.google.com/d/topic/sqlalchemy/ov-mYWA7XAM/unsubscribe. >>> To unsubscribe from this group and all its topics, 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. >>> >> >> > > -- > 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. > > > -- 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.