On May 24, 2007, at 10:02 AM, Patrick McKinnon wrote:
> sqlalchemy.exceptions.ArgumentError: Cant locate any foreign key
> columns in primary join condition 'attribute.child_id = child.id AND
> child.parent_id = parent.id' for relationship 'Parent.attributes
> (Attribute)'. Specify 'foreign_keys' argument to indicate which
> columns in the join condition are foreign.
0.3.7 is more strict about analyzing relationships and in this case
nothing in the join condition expresses a foreign key relationship
between the "parent" and "attribute" table. when only primaryjoin is
present, it assumes a one-to-many or many-to-one relationship between
two tables. what youre doing here is trying to "skip" over.
> parent_mapper = mapper(
> Parent,
> parent_table,
> properties = dict(
> children = relation(Child, backref='parent'),
> attributes = relation(Attribute,
> primaryjoin = and_(attribute_table.c.child_id ==
> child_table.c.id, child_table.c.parent_id == parent_table.c.id),
> backref = 'parent',
> )
> )
> )
>
so to "force" it:
parent_mapper = mapper(
Parent,
parent_table,
properties = dict(
children = relation(Child, backref='parent'),
attributes = relation(Attribute,
primaryjoin = and_(attribute_table.c.child_id ==
child_table.c.id, child_table.c.parent_id == parent_table.c.id),
foreign_keys=[attribute_table.c.child_id],
backref = backref('parent', foreign_keys=
[attribute_table.c.child_id], primaryjoin = and_
(attribute_table.c.child_id ==
child_table.c.id, child_table.c.parent_id ==
parent_table.c.id),),
)
)
)
however you want to put "viewonly=True" for the "attributes"
relationship, since that relationship will not persist correctly at all.
the "correct" way would be to just deal with the attributes
explicitly as they are attached to each child object. Normally id
try to use the "associationproxy" extension here but your
"attributes" property is actually the product of many individual
Child objects which is a little unusual.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---