Is there a way to model multiple objects using marshmallow sqlAlchemy?

231 views Asked by At

I have the following SqlAlchemy configuration (pseudo code for brevity):

class A(BaseModel):
   id: column...
   b_id: column...
   b: relationship...

class B(BaseModel):
   id: column...
   name: column...

class C(BaseModel):
   id: column...
   b_id: column...
   b: relationship...

I have a Marshmallow SqlAlchemy schema that looks like this:

class BSchema(SqlAlchemyAutoSchema):
   class Meta:
      model = B
      include_fk = True

class ASchema(SqlAlchemyAutoSchema):
   class Meta:
      model = A
      include_relationships = False
      include_fk = True
      load_instance = True
   b = Nested(BSchema, many=False)

The query that I'm using looks like this:

session.query(A, C.id)
   .join(B,A.b_id = B.id)
   .join(C,C.b_id = B.id)
   .all()

How can I include C.id in my ASchema class so I can access it later?

0

There are 0 answers