Hello wonderful community!
Today we're happy to announce
v1.1.0.rc1 release 🙌 , with the stable release (
v1.1.0) scheduled later this month.
Here's the last minor additions. This version is the feature freeze for
We added support for association aliases via
In this way an association can be referenced by the alias, not the conventional name.
class UserRepository < Hanami::Repository associations do has_many :stories has_many :comments end end
class CommentRepository < Hanami::Repository associations do belongs_to :story belongs_to :user, as: :author end end
class StoryRepository < Hanami::Repository associations do belongs_to :user has_many :comments has_many :users, through: :comments, as: :authors end def feed aggregate(:user, comments: :author).reverse(:created_at).map_to(Story) end end
In the example above,
StoryRepository can reference the author of a comment as
author, instead of
Entities as types in custom schema
Entities by default have a set of attributes (schema) which is the representation of a relation.
User will have all the columns of
users database table.
You can bypass this feature to build customize the attributes via custom schema.
Now you can use entities to be an attribute in a custom schema via
class Account < Hanami::Entity attributes do attribute :id, Types::Int attribute :owner, Types::Entity(User) end end
New option for model generator
We added a new option for the model generator:
% bundle exec hanami generate model user --relation=accounts create lib/bookshelf/entities/user.rb create lib/bookshelf/repositories/user_repository.rb create db/migrations/20171016124904_create_accounts.rb create spec/bookshelf/entities/user_spec.rb create spec/bookshelf/repositories/user_repository_spec.rb
It will generate a customized version of the database migration, and repository.
Hanami::Model.migration do change do create_table :accounts do primary_key :id column :created_at, DateTime, null: false column :updated_at, DateTime, null: false end end end
class UserRepository < Hanami::Repository self.relation = :accounts end
If you're using RSpec, the code generator will create specs with the
RSpec.describe Web::Controllers::Home::Index, type: :action do # ... end
Available types are:
We're grateful for each person who contributed to this release. These lovely people are:
- Alfonso Uceda
- Anton Davydov
- Luca Guidi
- Marcello Rocha
- Marion Duprey
- Marion Schleifer
- Oana Sipos
- Sean Collins
- Sergey Fedorov
- Yuji Ueki
How to try it
If you want to try with a new project:
gem install hanami --pre hanami new bookshelf
If you want to upgrade your existing project, edit the
# ... gem "hanami", "1.1.0.rc1" gem "hanami-model", "1.1.0.rc1"
We'll release the stable release later this month, in the meantime, please try this release candidate and report issues. Happy coding! 🌸