relations/dynamic loaders secondary argument not accepting classes

Issue #1455 resolved
Former user created an issue

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)

  1. Former user 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 ?

  2. Mike Bayer 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.

  3. Log in to comment