- Update logic to set a class's
__table_args__
(resp.__mapper_args__
), unless overridden, by merging (i)__global_table_args__
(resp.__global_mapper_args__
) from all classes in the class'smro()
with (ii)__local_table_args__
(resp.__local_mapper_args__
) from the class itself. (A__{global,local}_{table,mapper}_args__
may be callable or classmethod, in which case it is evaluated on the class whose__{table,mapper}_args__
is being set.) - Enhance logic for setting
__tablename__
to work with all table inheritance styles (joined, single, and concrete), to handle@declared_attr
columns, and not to duplicate underscores.
- Add support for callable
__table_args__
and__local_table_args__
. Thanks sethp!
- Add
Model.is_modified()
. Thanks sethp! - Add
Model.filter()
. - Add
Model.filter_by()
.
- Add
search.inenum
andsearch.notinenum
for performing anin_
andnot(in_)
comparision usingDeclarativeEnum
.
- Allow
Model.__bind_key__
to be set at the declarative base level so that model classes can properly inherit it.
- Make
ModelBase
's__table_args__
and__mapper_args__
inheritable via mixins. Thanks sethp! - Add
__enum_args__
toDeclarativeEnum
. Thanks sethp! - Allow enum name to be overridden when calling
DeclarativeEnum.db_type()
. Thanks sethp!
- During
Model.update()
when setting a non-list relationship automatically instantiatedict
values using the relationship model class.
- Convert null relationships to
{}
when callingModel.to_dict()
instead of leaving asNone
.
- During
Model.update()
when setting a list relationship automatically instantiatedict
values using the relationship model class.
- Allow
alias
keyword argument toQuery.join_eager()
andQuery.outerjoin_eager()
to be adict
mapping aliases to join keys. Enables nested aliases.
- Fix handling of nested
Model.update()
calls to relationship attributes so that setting relationship to emptydict
will propagateNone
to relationship attribute value correctly.
- Add
query.LoadOption
to support nesting load options when calling thequery.Query
load methods:join_eager
,outerjoin_eager
,joinedload
,immediateload
,lazyload
,noload
, andsubqueryload
.
- Replace usage of
@classproperty
decorators inModelBase
with@classmethod
. Any previously defined class properties now require method access. Affected attributes are:session
,primary_key
,primary_keys
,primary_attrs
,attrs
,descriptors
,relationships
,column_attrs
, andcolumns
. (breaking change) - Proxy
getitem
andsetitem
access togetattr
andsetattr
inModelBase
. Allows models to be accessed like dictionaries. - Make
alchy.events
decorators class based. - Require
alchy.events
decorators to be instantiated using a function call (e.g.@events.before_update()
instead of@events.before_update
). (breaking change) - Add
alchy.search
comparators,eqenum
andnoteqenum
, for comparingDeclarativeEnum
types.
- Fix
utils.iterflatten()
by callingiterflatten()
instead offlatten
in recursive loop.
- Add
ModelBase.primary_attrs
class property that returns a list of class attributes that are primary keys. - Use
ModelBase.primary_attrs
inQueryModel.search()
so that it handles cases where primary keys have column names that are different than the class attribute name.
- Modify internals of
QueryModel.search()
to better handle searching on a query object that already has joins and filters applied.
- Add
search.icontains
andsearch.noticontains
for case insensitive contains filter. - Remove strict update support from
Model.update()
. Require this to be implemented in user-land. (breaking change)
- Merge originating query where clause in
Query.search
so that pagination works properly. - Add
session_class
argument toManager
which can override the default session class used.
- In
ModelMeta
when checking whether to do tablename autogeneration, tranverse all base classes when trying to determine if a primary key is defined. - In
ModelMeta
setbind_key
in__init__
method instead of__new__
. This also fixes an issue where__table_args__
was incorrectly assumed to always be adict
.
- Support
order_by
as list/tuple inQueryModel.search()
.
- Fix bug in
QueryModel.search()
whereorder_by
wasn't applied in the correct order. Needed to come before limit/offset are applied.
- PEP8 compliance with default settings.
- Remove
query_property
argument frommake_declarative_base()
andextend_declarative_base()
. (breaking change) - Add
ModelBase.primary_keys
class property which returns a tuple always (ModelBase.primary_key
returns a single key if only one present or a tuple if multiple). - Move location of class
QueryProperty
fromalchy.model
toalchy.query
. (breaking change) - Create new
Query
subclass namedQueryModel
which is to be used within a query property context. ReplaceQuery
withQueryModel
as default query class. (breaking change) - Move
__advanced_search__
and__simple_search__
class attributes fromModelBase
toQueryModel
. (breaking change) - Introduce
QueryModel.__search_filters__
which can define a canonical set of search filters which can then be referenced in the list version of__advanced_search__
and__simple_search__
. - Modify the logic of
QueryModel.search()
to use a subquery joined onto the originating query in order to support pagination when one-to-many and many-to-many joins are present on the originating query. (breaking change) - Support passing in a callable that returns a column attribute for
alchy.search.<method>()
. Allows foralchy.search.contains(lambda: Foo.id)
to be used at the class attribute level whenFoo.id
will be defined later. - Add search operators
any_/notany_
andhas/nothas
which can be used for the corresponding relationship operators.
- Issue warning instead of failing when installed version of SQLAlchemy isn't compatible with
alchy.Query
's loading API (i.e. missingsqlalchemy.orm.strategy_options.Load
). This allowsalchy
to be used with earlier versions of SQLAlchemy at user's own risk. - Add
alchy.search
module which provides compatible search functions forModelBase.__advanced_search__
andModelBase.__simple_search__
.
- Change
ModelBase.session
to proxyModelBase.query.session
. - Add
ModelBase.object_session
proxy toorm.object_session(ModelBase)
.
- Remove
engine_config_prefix
argument toManager()
. (breaking change) - Add explicit
session_options
argument toManager()
. (breaking change) - Change the
Manager.config
options to follow Flask-SQLAlchemy. (breaking change) - Allow
Manager.config
to be either adict
,class
, ormodule object
. - Add multiple database engine support using a single
Manager
instance. - Add
__bind_key__
configuration option forModelBase
for binding model to specific database bind (similar to Flask-SQLAlchemy).
- For
ModelBase.update()
don't nestupdate()
calls if field attribute is adict
. - Deprecated
refresh_on_empty
argument toModelBase.to_dict()
and instead implementModelBase.__to_dict__
configuration property as place to handle processing of model before casting todict
. (breaking change) - Add
ModelBase.__to_dict__
configuration property which handles preprocessing for model instance and returns a set of fields as strings to be used as dict keys when callingto_dict()
.
- Rename
alchy.ManagerBase
toalchy.ManagerMixin
. (breaking change) - Add
pylint
support. - Remove dependency on
six
.
- Prefix event decorators which did not start with
before_
orafter_
withon_
. Specifically,on_set
,on_append
,on_remove
,on_append_result
,on_create_instance
,on_instrument_class
,on_mapper_configured
,on_populate_instance
,on_translate_row
,on_expire
,on_load
, andon_refresh
. (breaking change) - Remove lazy engine/session initialization in
Manager
. Require thatModel
andconfig
be passed in at init time. While this removes some functionality, it's done to simplify theManager
code so that it's more straightforward. If lazy initialization is needed, then a proxy class should be used. (breaking change)
- Add
ModelBase.primary_key
class property for retrieving primary key(s). - Add
Base=None
argument tomake_declarative_base()
to support passing in a subclass ofModelBase
. Previously had to create a declarativeModel
to pass in a subclassedModelBase
. - Let any exception occurring in
ModelBase.query
attribute access bubble up (previously,UnmappedClassError
was caught). - Python 2.6 and 3.3 support.
- PEP8 compliance.
- New dependency:
six
(for Python 3 support)
- In
ModelBase.to_dict()
only include fields which are mapper descriptors. - Support
to_dict
method hook when iterating over objects inModelBase.to_dict()
. - Add
to_dict
method hook toEnumSymbol
(propagates toDeclarativeEnum
).
- Support
__iter__
method in model so thatdict(model)
is equilvalent tomodel.to_dict()
. - Add
refresh_on_empty=True
argument toModelBase.to_dict()
which supports callingModelBase.refresh()
if__dict__
is empty.
- Add
ModelBase.save()
method which adds model instance loaded from session to transaction. - Add
ModelBase.get_by()
which proxies toModelBase.query.filter_by().first()
. - Add model attribute
events
. - Add support for multiple event decoration.
- Add named events for all supported events.
- Add composite events for
before_insert_update
andafter_insert_update
.
- Rename
ModelBase.advanced_search_config
toModelBase.__advanced_search__
. - Rename
ModelBase.simple_search_config
toModelBase.__simple_search__
- Add
ModelMeta
metaclass. - Implement
__tablename__
autogeneration from class name. - Add mapper event support via
ModelBase.__events__
and/ormodel.event
decorator.
- Fix reference to
model.make_declarative_base
inManager
class.
- Add default
query_class
to declarative model if none defined. - Let
model.make_declarative_base()
accept predefined base and just extend its functionality.
- First release