views:

19

answers:

1

I'm using Elixir with SQLite and I'd like to perform multiple inserts as per the docs:

http://www.sqlalchemy.org/docs/05/sqlexpression.html#executing-multiple-statements

However, my ManyToMany relationship is self-referential and I can't figure out where to get the insert() object from. Can anyone help?

Thanks!

A: 

It might be easy if you just stick with SQL Alchemy's built in Declarative style instead of using Elixir as much of what it does is now doable in there. Then you can follow the example here: Many to Many

Then look very closely at the code where a post is added and then keywords related to that post are added. You get multiple inserts done for you into the relator table - the one that maintains the many to many relationship:

>>> post.keywords.append(Keyword('wendy'))
>>> post.keywords.append(Keyword('firstpost'))
Khorkrak
Hmm, doesn't that mean I'd need to recreate my table, though? I should have done that from the beginning, but now I just want to perform some bulk inserts...
Stavros Korokithakis
The table is the object that has the insert method on it. You can get to the table object by referencing the class's "__table__" attribute. For example skim through this [Another Tutorial](http://www.blog.pythonlibrary.org/2010/02/03/another-step-by-step-sqlalchemy-tutorial-part-2-of-2/) # get a handle on the table object users_table = User.__table__
Khorkrak