Hi,

I'm still having troubles correctly figuring my various many-to-many
relations. Originally, this was a 'standard' many-to-many; that is, a
secondary table was specified.

However, I now need to add further information to the relation and am
converting into an AssociationObject. My problem is in ensuring that the
original calls still work. So, currently I have:

class Association(Base):

    __tablename__ = 'objecta_objectb'
    objecta_id = Column(Integer, ForeignKey('objecta.id'), primary_key=True)
    objectb_id = Column(Integer, ForeignKey('objectb.id'), primary_key=True)
    objecta = relationship("ObjectA", backref = "associations", cascade =
'all, delete-orphan')
    objectb = relationship("ObjectB", backref = "associations", cascade =
'all, delete-orphan')

    def __init__(self, objecta = None, objectb = None):
        self.objecta = objecta
        self.objectb = objectb
        pass

class ObjectA(Base):
    objectbs = association_proxy('associations', 'objectb', creator=lambda
b:
            Association(objectb=b))

class ObjectB(Base):
    objectas = association_proxy('associations', 'objecta', creator=lambda
a:
            Association(objecta=a))

The point of all this is so that I can create the associations by doing:

objecta_instance.objectbs.append(objectb_instance)

or
association_instance = Association(objectb = objectb_instance)
objecta_instance.associations.append(association_instance)

Sorry if the above is rather convoluted; it is based on
http://www.preetk.com/node/sqlalchemy-part-2-declarative-bi-directional-association-classes/,
which is somewhat clearer.

Anyway, using the above I get:

AssertionError: Dependency rule tried to blank-out primary key column
'objecta_objectb.objectb_id' on instance '<Association at 0x109277b90>'

What am I doing wrong? I understand that it is somehow related to how the
cascade is set up, but I'm not sure how to move forward.

Thanks,
Ben

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to