lib/hanami/model/mapped_relation.rb in hanami-model-1.2.0.beta2 vs lib/hanami/model/mapped_relation.rb in hanami-model-1.2.0.rc1

- old
+ new

@@ -24,10 +24,36 @@ end # @since 1.0.0 # @api private def initialize(relation) + @relation = relation super(relation.as(self.class.mapper_name)) + end + + # Access low level relation's attribute + # + # @param attribute [Symbol] the attribute name + # + # @return [ROM::SQL::Attribute] the attribute + # + # @raises [Hanami::Model::UnknownAttributeError] if the attribute cannot be found + # + # @since 1.2.0 + # + # @example + # class UserRepository < Hanami::Repository + # def by_matching_name(name) + # users + # .where(users[:name].ilike(name)) + # .map_to(User) + # .to_a + # end + # end + def [](attribute) + @relation[attribute] + rescue KeyError => e + raise UnknownAttributeError.new(e.message) end end end end