How to use the marshmallow-sqlalchemy.fields.get_primary_keys function in marshmallow-sqlalchemy

To help you get started, we’ve selected a few marshmallow-sqlalchemy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github raminfp / PYHelper / marshmallow-sqlalchemy / schema.py View on Github external
def get_instance(self, data):
        """Retrieve an existing record by primary key(s)."""
        props = get_primary_keys(self.opts.model)
        filters = {
            prop.key: data.get(prop.key)
            for prop in props
        }
        if None not in filters.values():
            return self.session.query(
                self.opts.model
            ).filter_by(
                **filters
            ).first()
        return None