Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Many-to-many issue #20

Open
sobolevn opened this issue Dec 16, 2015 · 1 comment
Open

Many-to-many issue #20

sobolevn opened this issue Dec 16, 2015 · 1 comment

Comments

@sobolevn
Copy link

I have faced an issue with Flask's db.Table. Here's my setup:

# models.py:
class Project(db.Model):
        id = db.Column(db.Integer, primary_key=True)
    interviewers = db.relationship('User', secondary='project_interviewer')

project_interviewer = db.Table(
    'project_interviewer',
    db.Column('user_id', db.Integer, db.ForeignKey('user.id')),
    db.Column('project_id', db.Integer, db.ForeignKey('project.id')),
)

Now I am trying to load project from the fixtures:

[{
  "model": "merku.models.Project",
  "records": [
    { "id": 1 }
  ]
}, {
  "table": "project_interviewer",
  "records": [
    {
      "id": 1,
      "project_id": 1,
      "user_id": 2
    }
  ]
}]

It was not loading. After some digging I have found out that the issue was here:

# flask_fixtures/__init__.py line: 82
table = Table(fixture['table'], metadata)

After looking inside this object, it became clear, that it was not creating any columns. So, the generated query was: INSERT INTO project_interviewer () VALUES ().

I have made this to work with:

table = Table(fixture['table'], metadata,
                      autoload=True, autoload_with=db.engine)
for record in fixture['records']:  
    # there was an issue 'default engine does not support multi-line inserts':
    conn.execute(table.insert(), record)

Maybe I have missed something?

@sobolevn
Copy link
Author

After running tests with my fix:

___________________________________ summary ____________________________________
ERROR: py26: InterpreterNotFound: python2.6
py27: commands succeeded
py34: commands succeeded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant