Comments (2)
The problem is where using backref
from restfulpy.
hmm, solved (using restfulpy.orm.relation -> separate relations -> protect relation on child table):
from sqlalchemy import Column, String, Integer, create_engine, ForeignKey, MetaData
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import Session
from restfulpy.orm import BaseModel, relationship
metadata = MetaData()
Base = declarative_base(cls=BaseModel, metadata=metadata)
class Employee(Base):
__tablename__ = 'employee'
id = Column(Integer, primary_key=True)
name = Column(String(50))
type = Column(String(20))
images = relationship('Image', secondary='image_relations', back_populates='employee')
class Image(Base):
__tablename__ = 'images'
id = Column(Integer, primary_key=True)
src = Column(String(100))
employee = relationship('Employee', secondary='image_relations', back_populates='images', protected=True)
class ImageRelation(Base):
__tablename__ = 'image_relations'
employee_id = Column(Integer, ForeignKey('employee.id'), primary_key=True)
image_id = Column(Integer, ForeignKey('images.id'), primary_key=True)
engine = create_engine('sqlite://', echo=True)
Base.metadata.create_all(engine)
session = Session(engine, autoflush=False, autocommit=False, expire_on_commit=True)
@Employee.expose
def run():
emp1 = Employee()
emp1.id = 1
emp1.name = 'dia gram'
emp1.images.append(Image(src='lorem.com'))
session.add(emp1)
session.commit()
return emp1
print(run().to_dict())
from restfulpy.
Related Issues (20)
- Review StatefulAuthenticator HOT 1
- JSON Patch empty form
- Output filename in wiki
- Email fields length constraint
- Implementing Schedulability feature for RestfulpyTask (v3.0.0)
- Implementing Reschedulability feature for RestfulpyTask (v3.0.0) HOT 2
- Bug in FieldInfo.to_json()
- Migrate to easycli
- Bug on commit decorator while redirection HOT 2
- Bug on commit decorator while raise 2xx statuses
- Completely purge logging module
- Completely purge ERD generator
- Completely purge mimetypes sub-module
- Commit decorator rollback session on raise 2xx and 3xx statuses HOT 1
- Travis does not work on release/v2 branch and its PRs HOT 1
- TODOs and FIXMEs HOT 1
- Bug on application CLI main
- Replace deprecated sqlalchemy methods HOT 1
- Purge scaffolding
- Checking equality of user id of an expired jwt tokens with the refresh token
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from restfulpy.