Adrian <adr...@planetcoding.net> wrote:
> > the model here doesn’t illustrate how this would be a many-to-many. > A User can have any number of other Users as a favorite. That looks quite > many-to-many to me…. then you are referring to a self-referential User -> favorite_user -> User relationship which is M2M but then I don’t see why you need all the complexity of using a mixin for a “FavoriteUser”. > This is a simplified version of my structure: > > User: > - serial id (pk) > - bool is_deleted > > FavoriteUser > - user_id (pk, fk to User.id) > - target_id (pk, fk to User.id) > > > yeah that’s the lambda + string together which is not the correct use. > If i put just a string I get the same: > sqlalchemy.exc.ArgumentError: Column-based expression object expected for > argument 'primaryjoin'; got: '(User.id == user_id) & ~target.is_deleted', > type <type 'unicode'> > With a lamda there error is gone though. That's one step closer :) There’s no way you get that error unless you still have a lambda + string together, provided the class is mapped with declarative. The relationship will pass using a form such as: @declared_attr def user(cls): """The user owning this favorite""" return relationship( 'User', lazy=False, foreign_keys=lambda: [cls.user_id], backref=backref( '_favorite_{}'.format(cls._type), lazy=True, cascade='all, delete-orphan', primaryjoin=lambda: (User.id == cls.user_id) & ~User.is_deleted ) ) > > I guess with the way I have my relationships setup at the moment, I'd need to > access the join from the `target` relationship from the backref of the `user` > relationship? > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sqlalchemy+unsubscr...@googlegroups.com. > To post to this group, send email to sqlalchemy@googlegroups.com. > Visit this group at http://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.