Hi All,

I currently have code that looks like this:

recipients = []
if recipient_ids:
   for id in recipient_ids.split(','):
      recipients.append(
          session.query(recipient.Recipient).filter_by(id=id).one()
      )
else:
    recipient_ids = ()
feed.recipients = recipients

Where the models are:

feed_recipient = Table('feed_recipient', Base.metadata,
    Column('feed_id', String(length=32), ForeignKey('feed.id')),
    Column('recipient_id', Integer, ForeignKey('recipient.id')),
    )

class Feed(Base):
    __tablename__ = 'feed'
    id = Column(String(length=32), primary_key=True)
    recipients = relation('Recipient', secondary=feed_recipient)

class Recipient(Base,ComputedMapperArgs):
    __tablename__='recipient'
    feeds = relation('Feed', secondary=feed_recipient)

It feels like a horribly inefficient way of updating the many-to-many relationship. I guess I could just use the sql abstraction layer, but that feels like circumventing the ORM without just cause ;-)

Am I missing something? If I have a sequence of ids where I want to update the many to many relationship as above, what's the best way of doing it?

cheers,

Chris

--
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.

Reply via email to