I'm trying to allow users to 'favorite' different items in my web app. So, for example, a user can favorite a comment and favorite a news story. I then want to query all of the items a user has favorited, and load the associated objects (whether it be a news story or comment etc) polymorphically to display the list of objects to the user. I know how to create a one to one polymorphic relationship, however I have not been able to figure out many to many.
Thanks in advance
EDIT
In my one-to-one polymorphic relationship I have a one-many relation between users and user actions, and a one-one polymorphic relationship between user actions and the object the action was performed on. So in this case my user action table is like so:
class UserAction:
pass
user_actions = Table('user_action', metadata,
Column('id', Integer, autoincrement=True, primary_key=True),
Column('module', String(30)),
Column('created', DateTime, default=datetime.now),
Column('user_id', Integer, ForeignKey('user.id'))
)
news table (one of the objects that can be accessed via a user action):
class News:
pass
news = Table('news', metadata,
Column('id', Integer, autoincrement=True, primary_key=True),
Column('title', String(30), nullable=False),
Column('action_id', Integer, ForeignKey('user_action.id'))
)
And the mappers:
mapper(UserAction, user_actions, polymorphic_on=user_actions.c.module, polymorphic_identity='user_action')
mapper(News, news, inherits=UserAction, polymorphic_identity='news')
As you can see, there is a clear one-one relation between a news object and the user_action record associated with it. This is because the user_action foreign key is in the news table. If I wanted to go about creating a a many to many polymorphic relation where multiple different object types can be favorited by many users how would I go about doing this? Thanks so much.