You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Basically I would like to add a new nested relation to an schema, that I already use in other services, without this implying a change to the rest of the functionalities that use it for serialization. Since I work with sqlalchemy, if I include the new relation, new unwanted statements appears everywhere, since the ORM tries to fill it. I would need something like adding the relation, and specifying that be only included if I specify it. I seen this kind of problem resolved in other libraries using groups annotations, so in this case, the relation is added, annotated with a new group, and them call serialize using the existing groups plus the new one.
Note: Create a new schema is not a good solution since the affected schema is deep in the relation, so I would have to create all it's fathers too.
The text was updated successfully, but these errors were encountered:
I'm having trouble understanding your use case. Could you provide an example of the changes you want to make to the nested schema?
Per the not creating a new schema constraint, creating a factory method that builds a schema class would allow you to customize the schema without duplicating it.
Let say I have this schema for a sale, and use it in some operations.
class SaleSchema(ma.SQLAlchemySchema):
class Meta:
model = Sale
include_relationships = True
load_instance = True
id = ma.auto_field()
created_at = ma.auto_field()
product_id = ma.auto_field()
product = fields.Nested('ProductSchema')
class ProductSchema(ma.SQLAlchemySchema):
class Meta:
model = Product
include_relationships = True
load_instance = True
id = ma.auto_field()
name = ma.auto_field()
But as the project grow a new operation appears with the need of serialize some product's links, so the new ProductSchema should be:
class ProductSchema(ma.SQLAlchemySchema):
class Meta:
model = Product
include_relationships = True
load_instance = True
id = ma.auto_field()
name = ma.auto_field()
products_links = fields.Nested('ProductLinkSchema', many=True)
This is a serious problem if you are using sqlalchemy since a new query is executed for each sale serialized, searching for it's product's links. I don't see a way of do that without affect the existing functionality. The only option is to create a new version of product schema every time this situation occurs. I know about exclude option, but modify the already tested code is not seems good.
Serializations groups is the solution I've seen on other frameworks. Each field of the schema can be marked with groups, and you can specify serialize/deserialize all, or specify some groups. Then, when a new relation or new fields appears, you have the option to mark it with the same group, if you want to modify the existing functionalities, or with a new group to be used from now on.
Basically I would like to add a new nested relation to an schema, that I already use in other services, without this implying a change to the rest of the functionalities that use it for serialization. Since I work with sqlalchemy, if I include the new relation, new unwanted statements appears everywhere, since the ORM tries to fill it. I would need something like adding the relation, and specifying that be only included if I specify it. I seen this kind of problem resolved in other libraries using groups annotations, so in this case, the relation is added, annotated with a new group, and them call serialize using the existing groups plus the new one.
Note: Create a new schema is not a good solution since the affected schema is deep in the relation, so I would have to create all it's fathers too.
The text was updated successfully, but these errors were encountered: