summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/__init__.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-08-14 14:52:18 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2010-08-14 14:52:18 -0400
commit8fc50cd3a4eb98501c5ae47ead07c20b485934df (patch)
tree45f85f8e07deeb8430c0ef60f5534d5eff15b57f /lib/sqlalchemy/orm/__init__.py
parent252ab17c7dc5f1cfd1a5173fb6d9e4b819e1ebb7 (diff)
downloadsqlalchemy-8fc50cd3a4eb98501c5ae47ead07c20b485934df.tar.gz
- Another pass through the series of error messages
emitted when relationship() is configured with ambiguous arguments. The "foreign_keys" setting is no longer mentioned, as it is almost never needed and it is preferable users set up correct ForeignKey metadata, which is now the recommendation. If 'foreign_keys' is used and is incorrect, the message suggests the attribute is probably unnecessary. Docs for the attribute are beefed up. This because all confused relationship() users on the ML appear to be attempting to use foreign_keys due to the message, which only confuses them further since Table metadata is much clearer. - If the "secondary" table has no ForeignKey metadata and no foreign_keys is set, even though the user is passing screwed up information, it is assumed that primary/secondaryjoin expressions should consider only and all cols in "secondary" to be foreign. It's not possible with "secondary" for the foreign keys to be elsewhere in any case. A warning is now emitted instead of an error, and the mapping succeeds. [ticket:1877] - fixed incorrect "Alternate Collection Mappings" reference in the docs, not sure if someone wants to reference "Rows that Point to Themselves" function - "Collection Mapping" is "Advanced Collection Mapping", this section is troublesome since nobody really needs it but it is public API
Diffstat (limited to 'lib/sqlalchemy/orm/__init__.py')
-rw-r--r--lib/sqlalchemy/orm/__init__.py27
1 files changed, 18 insertions, 9 deletions
diff --git a/lib/sqlalchemy/orm/__init__.py b/lib/sqlalchemy/orm/__init__.py
index 2004dccd1..c74fabacd 100644
--- a/lib/sqlalchemy/orm/__init__.py
+++ b/lib/sqlalchemy/orm/__init__.py
@@ -274,15 +274,24 @@ def relationship(argument, secondary=None, **kwargs):
:param foreign_keys:
a list of columns which are to be used as "foreign key" columns.
- this parameter should be used in conjunction with explicit
- ``primaryjoin`` and ``secondaryjoin`` (if needed) arguments, and
- the columns within the ``foreign_keys`` list should be present
- within those join conditions. Normally, ``relationship()`` will
- inspect the columns within the join conditions to determine
- which columns are the "foreign key" columns, based on
- information in the ``Table`` metadata. Use this argument when no
- ForeignKey's are present in the join condition, or to override
- the table-defined foreign keys.
+ Normally, :func:`relationship` uses the :class:`.ForeignKey`
+ and :class:`.ForeignKeyConstraint` objects present within the
+ mapped or secondary :class:`.Table` to determine the "foreign" side of
+ the join condition. This is used to construct SQL clauses in order
+ to load objects, as well as to "synchronize" values from
+ primary key columns to referencing foreign key columns.
+ The ``foreign_keys`` parameter overrides the notion of what's
+ "foreign" in the table metadata, allowing the specification
+ of a list of :class:`.Column` objects that should be considered
+ part of the foreign key.
+
+ There are only two use cases for ``foreign_keys`` - one, when it is not
+ convenient for :class:`.Table` metadata to contain its own foreign key
+ metadata (which should be almost never, unless reflecting a large amount of
+ tables from a MySQL MyISAM schema, or a schema that doesn't actually
+ have foreign keys on it). The other is for extremely
+ rare and exotic composite foreign key setups where some columns
+ should artificially not be considered as foreign.
:param innerjoin=False:
when ``True``, joined eager loads will use an inner join to join