- changed status to wontfix
relations/dynamic loaders secondary argument not accepting classes
The secondary/intermediary table in relations cannot be specified using a declarative class name, instead the underlying table must be given: class.table This syntax is undesirable, and is avoided in many other places, why not here?
Error raised is: AttributeError: 'name' object has no attribute 'foreign_keys'
Comments (3)
-
repo owner -
Account Deleted any chance of a slightly more detailed explanation? why would the orm attempt to insert/delete twice? could a simple check not be added to the secondary argument to realise that the argument passed is a class and automatically check that the argument has a table ?
-
repo owner Replying to guest:
any chance of a slightly more detailed explanation? why would the orm attempt to insert/delete twice?
because the association classes' mapper sees a new record and will perform an INSERT, then the relation that is acting on the table as a secondary item may also detect items added to the collection and INSERT the same rows, if you've created records in both places. Similarly if you delete the parent item and you have cascade onto the association mapper, that's one DELETE, then the relation() issues a redundant DELETE and fails.
could a simple check not be added to the secondary argument to realise that the argument passed is a class and automatically check that the argument has a table ?
mapped classes should not be passed as the "secondary" argument, it would be encouraging a common mistake.
- Log in to comment
this is because you should never specify a mapped class as the "secondary" argument in a relation. The ORM will attempt to insert/delete from the row twice. I recall creating a ticket to someday "detect" when a Table is used in both places and to raise an error but I can't seem to find it. Anyway this notion is documented at the end of http://www.sqlalchemy.org/docs/05/mappers.html#association-object .