Yes Mike will do that, mostly its marshmallow model schema which is
creating the object, as I am using Flask + marshmallow for APIs,
apart from that I have another issue, which i am not able to uderstand:
I have a many-to-many relationship between 2 models, same as posted above,
still ill put the models here
package model:
class Package(db.Model, BaseMixin):
__tablename__ = 'packages'
__bind_key__ = 'broker_db'
__repr_attrs__ = ["id","name","deletepkg"]
__track_attrs__ = ["name","versions"]
#attributes
id = db.Column(db.Integer, primary_key=True,
autoincrement=True)
name = db.Column(db.String(100),
index=True,unique=True, nullable=False)
deletepkg = db.Column(db.Boolean,
index=True,nullable=False)
instances = db.relationship('Instance',
cascade="all,delete",secondary=PACKAGE_INSTANCE_RELATION,back_populates="packages")
groups = db.relationship('Group',cascade="all,delete",
secondary=PACKAGE_GROUP_RELATION,back_populates="packages")
versions = db.relationship('Version',lazy='dynamic')
events = db.relationship('Event',
backref=db.backref('package', uselist=False),lazy='dynamic')
group model:
PACKAGE_GROUP_RELATION = db.Table('package_group_relation',
db.Column('package_id', db.Integer, db.ForeignKey('packages.id')),
db.Column('groupt_id', db.Integer, db.ForeignKey('groupts.id')),
info={'bind_key': 'broker_db'}
)
class Group(db.Model,BaseMixin):
__tablename__ = 'groupts'
__repr_attrs__ = ["id","name"]
__bind_key__ = 'broker_db'
__track_attrs__ = ["name","packages"]
id = db.Column(db.Integer, primary_key=True,
autoincrement=True)
name = db.Column(db.String(100),unique=True)
packages =
db.relationship("Package",cascade="all,delete",secondary=PACKAGE_GROUP_RELATION,back_populates="groups")
events = db.relationship('Event',
backref=db.backref('group', uselist=False), lazy='dynamic')
def __init__(self, name):
self.name = name
in this model when i do something like this:
p = Package.query.filter_by(name='firefox').first() //here p is
Package object, and it has some groups mapped to it
p.groups=[] //when i try to empty it, i get this exception
*AssertionError: Collection was loaded during event
handling. *//though the action is getting
performed, putting a try catch is solving it, but why is it coming?
though,
g.packages=[] this is working fine with no exception
Thanks for any kind of help, in advance
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.