エンティティ間の関係の実装方法(例:1対多、多対多など)を検索しましたが、見つからなかった任意の例。花見との多対多関係の実装
だから私は合理的な推測を試みた。ここでTag
秒でタグ付けすることができPerson
実装での私の試みです:
require 'moocho_query'
require 'hanami/model'
require 'hanami/model/adapters/file_system_adapter'
class Person
include Hanami::Entity
attributes :name, :age, :tags
end
class Tag
include Hanami::Entity
attributes :name
end
class PersonRepository
include Hanami::Repository
end
class TagRepository
include Hanami::Repository
end
Hanami::Model.configure do
adapter type: :file_system, uri: './file_db'
mapping do
collection :people do
entity Person
repository PersonRepository
attribute :id, Integer
attribute :name, String
attribute :age, Integer
attribute :tags, type: Array[Tag]
end
collection :tags do
entity Tag
repository TagRepository
attribute :id, Integer
attribute :name, String
end
end
end.load!
me = Person.new(name: 'Jonah', age: 99)
t1 = Tag.new(name: 'programmer')
t2 = Tag.new(name: 'nice')
me.tags = [t1, t2]
PersonRepository.create(me)
これは、次のエラーで、load!
呼び出しに失敗:何ですか
/Users/x/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/hanami-utils-0.7.0/lib/hanami/utils/class.rb:90:in `load_from_pattern!': uninitialized constant (Hanami::Model::Mapping::Coercers::{:type=>[Tag]}|
{:type=>[Tag]}) (NameError)
from /Users/jg/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/hanami-model-0.6.0/lib/hanami/model/mapping/attribute.rb:80:in `coercer'
from /Users/jg/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/hanami-model-0.6.0/lib/hanami/model/mapping/attribute.rb:53:in `load_coercer'
に関係を実装するための正しい方法花見?
ありがとうございました。 Hanamiのようなファイル/メモリ/ postgresのための交換可能なアダプタを持つリポジトリパターンを実装する他のルビーの宝石は知っていますが、関連をサポートしていますか? – Jonah