Code Monkey home page Code Monkey logo

Comments (3)

eoyilmaz avatar eoyilmaz commented on August 18, 2024

Your query is not correct in:

for user in User.query.filter_by(name='Peter Griffin'):
    user.companies = companies

User.query.filter_by(name='Peter Griffin') returns a query object not an array of User instances, you should use User.query.filter_by(name='Peter Griffin').all().

And in fact it is a weird query, do you have more than one user named "Peter Griffin"? If not you should be using somthing like:

peter = User.query.filter_by(name='Peter Griffin').first()
peter.companies = companies

from stalker.

fredrikaverpil avatar fredrikaverpil commented on August 18, 2024

User.query.filter_by(name='Peter Griffin') returns a query object not an array of User instances, you should use User.query.filter_by(name='Peter Griffin').all().

Yes, that syntax was a bit weird, perhaps. But if you disregard that syntax (which still demonstrates the issue) I'm getting the same error when using your suggested syntax:

from stalker import db, User, Project, Role, Client, DepartmentUser, ClientUser, ProjectUser
db.setup()

companies = []
for client in Client.query.all():
    companies.append(client)
print companies # returns: [<Acme (Client)>, <Quahog (Client)>]

user = User.query.filter_by(name='Peter Griffin').first()
print type(user) # returns: <class 'stalker.models.auth.User'>
print user.name # returns: Peter Griffin
print user.companies # returns: [<Acme (Client)>]
user.companies = companies
print user.companies # returns: [<Acme (Client)>, <Quahog (Client)>]

db.DBSession.commit() # <--- Causes an error "AssertionError: Dependency rule tried to blank-out primary key column 'Client_Users.uid' on instance '<ClientUser at 0x564d320>'"

If you comment db.DBSession.commit() out, there is no error (but then the change is also not saved).
I've upgraded to cbfa106.

from stalker.

fredrikaverpil avatar fredrikaverpil commented on August 18, 2024

This issue should not be closed.

It is not possible to commit a modification to User.companies, as described in my previous comment.

from stalker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.