Search code examples
pythonsqlrubyactiverecordpython-elixir

Is there an equivalent of ActiveRecord's find(:include) in Elixir/SQLAlchemy?


I had been using ActiveRecord previously and it allowed to load all associations of an object using an optional :include argument to its dynamic finders. I have recently started using Elixir for a python project and am unable to find any documentation that'd suggest if it's possible to do the same.


Solution

  • Using plain SQLAlchemy (without Elixir): http://www.sqlalchemy.org/docs/orm/loading.html

    I assume you can configure the loading strategies using Elixir as well, but I have never used it.

    EDIT 1:

    According to the Elixir documentation, options to the relationship constructs (for instance ManyToOne) can include options that are passed directly to the SQLAlchemy relation (relationship if version >= 0.6) function. That means you can specify the lazy option to control the loading for associated objects.

    I assume that Elixir's query method is a thin wrapper around SQLAlchemy's. In that case, you can also control lazy/eager loading for individual queries. See the documentation.

    EDIT 2:

    Have you considered using sqlalchemy.ext.declarative instead of Elixir?