+++++++++++++++++++
Features:
* Add ``SQLAlchemySchema`` and ``SQLAlchemyAutoSchema``,
which have an improved API for generating marshmallow fields
and overriding their arguments via ``auto_field`` (:issue:`240`).
Thanks :user:`taion` for the idea and original implementation.
.. code-block:: python
Before
from marshmallow_sqlalchemy import ModelSchema, field_for
from . import models
class ArtistSchema(ModelSchema):
class Meta:
model = models.Artist
id = field_for(models.Artist, "id", dump_only=True)
created_at = field_for(models.Artist, "created_at", dump_only=True)
After
from marshmallow_sqlalchemy import SQLAlchemySchema, auto_field
from . import models
class ArtistSchema(SQLAlchemyAutoSchema):
class Meta:
model = models.Artist
id = auto_field(dump_only=True)
created_at = auto_field(dump_only=True)
* Add ``load_instance`` option to configure deserialization to model instances (:issue:`193`, :issue:`270`).
* Add ``include_relationships`` option to configure generation of marshmallow fields for relationship properties (:issue:`98`).
Thanks :user:`dusktreader` for the suggestion.
Deprecations:
* ``ModelSchema`` and ``TableSchema`` are deprecated,
since ``SQLAlchemyAutoSchema`` has equivalent functionality.
.. code-block:: python
Before
from marshmallow_sqlalchemy import ModelSchema, TableSchema
from . import models
class ArtistSchema(ModelSchema):
class Meta:
model = models.Artist
class AlbumSchema(TableSchema):
class Meta:
table = models.Album.__table__
After
from marshmallow_sqlalchemy import SQLAlchemyAutoSchema
from . import models
class ArtistSchema(SQLAlchemyAutoSchema):
class Meta:
model = models.Artist
include_relationships = True
load_instance = True
class AlbumSchema(SQLAlchemyAutoSchema):
class Meta:
table = models.Album.__table__
* Passing `info={"marshmallow": ...}` to SQLAlchemy columns is deprecated, as it is redundant with
the ``auto_field`` functionality.
Other changes:
* *Backwards-incompatible*: ``fields_for_model`` does not include relationships by default.
Use ``fields_for_model(..., include_relationships=True)`` to preserve the old behavior.