On Aug 12, 2010, at 4:58 PM, Alvaro Reinoso wrote: > I'm still working on the solution. I've found out some stuff in > internet. I guess I'm close to, but I haven't got it yet. I'm using > this for the relation: > > mediaGroups = relationship("MediaGroup", > secondary=media_group_groups, order_by="MediaGroup.title", > backref='media_groups', foreign_keys = > ["media_group_groups.groupA_id", "media_group_groups.groupB_id"], > primaryjoin = "MediaGroup.id == > media_group_groups.groupA_id", > secondaryjoin = "MediaGroup.id == media_group_groups.groupB_id") > > I'm playing with the parameters, but I usually get this error: > > "ArgumentError: Could not determine relationship direction for > primaryjoin condition 'users.id = :id_1', on relationship > User.mediaGroups. Specify the 'foreign_keys' argument to indicate > which columns on the relationship are foreign."
"media_group_groups" is not available when "primaryjoin" is evaluated as a string, nor within "foreign_keys" which is not necessary here since your meta_group_groups already has ForeignKey objects on it, so use a non-string format for primaryjoin. i will add additional examples to the declarative docs. > > Thank you! > > On Aug 12, 1:08 pm, Alvaro Reinoso <alvrein...@gmail.com> wrote: >> Hello, >> >> I'm trying to link one table to itself. I have media groups which can >> contain more media group. I created a relation many to many: >> >> media_group_groups = Table( >> "media_group_groups", >> metadata, >> Column("groupA_id", Integer, >> ForeignKey("media_groups.id")), >> Column("groupB_id", Integer, >> ForeignKey("media_groups.id")) >> ) >> >> class MediaGroup(rdb.Model): >> """Represents MediaGroup class. Conteins channels and other media >> groups""" >> rdb.metadata(metadata) >> rdb.tablename("media_groups") >> >> id = Column("id", Integer, primary_key=True) >> title = Column("title", String(100)) >> parents = Column("parents", String(512)) >> >> channels = relationship(Channel, secondary=media_group_channels, >> order_by=Channel.titleView, backref="media_groups") >> mediaGroup = relationship("MediaGroup", >> secondary=media_group_groups, order_by="MediaGroup.title", >> backref="media_groups") >> >> I got this error: >> >> "ArgumentError: Could not determine join condition between parent/ >> child tables on relationship MediaGroup.mediaGroup. Specify a >> 'primaryjoin' expression. If this is a many-to-many relationship, >> 'secondaryjoin' is needed as well." >> >> When I create the tables I don't get any error, it's just when I add >> any element to it. >> Any idea??? >> >> Thanks in advance! > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to sqlalch...@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. > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@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.