0
@@ -47,35 +47,38 @@ module DataMapper
0
attr_reader :relationships, :model, :property
0
- def initialize(repository, relationships, model_name, property_name = nil)
0
- raise ArgumentError, "+repository+ is not a Repository, but was #{repository.class}", caller unless Repository === repository
0
- raise ArgumentError, "+relationships+ is not an Array, but was #{relationships.class}", caller unless Array === relationships
0
- raise ArgumentError, "+model_name+ is not a Symbol, but was #{model_name.class}", caller unless Symbol === model_name
0
- raise ArgumentError, "+property_name+ is not a Symbol, but was #{property_name.class}", caller unless Symbol === property_name || property_name.nil?
0
+ def initialize(repository, relationships, model, property_name = nil)
0
+ raise ArgumentError, "+repository+ is not a Repository, but was #{repository.class}", caller unless Repository === repository
0
+ raise ArgumentError, "+relationships+ is not an Array, it is a #{relationships.class}", caller unless Array === relationships
0
+ raise ArgumentError, "+model+ is not a DM::Resource, it is a #{model}", caller unless model.ancestors.include?(DataMapper::Resource)
0
+ raise ArgumentError, "+property_name+ is not a Symbol, it is a #{property_name.class}", caller unless Symbol === property_name || property_name.nil?
0
@repository = repository
0
@relationships = relationships
0
- @model =
Inflection.classify(model_name.to_s).to_class0
@property = @model.properties(@repository.name)[property_name] if property_name
0
- alias_method :_method_missing, :method_missing
0
def method_missing(method, *args)
0
- if @model.relationships(@repository.name).has_key?(method)
0
+ if relationship = @model.relationships(@repository.name)[method]
0
+ clazz = if @model == relationship.child_model
0
+ relationship.parent_model
0
+ relationship.child_model
0
relations.concat(@relationships)
0
- relations << @model.relationships(@repository.name)[method]
0
- return DataMapper::Query::Path.new(@repository, relations,method)
0
+ relations << relationship #@model.relationships[method]
0
+ return Query::Path.new(@repository, relations,clazz)
0
- if @model.properties(@repository.name)[method]
0
- @property = @model.properties(@repository.name)[method]
0
+ if @model.properties(@model.repository.name)[method]
0
+ @property = @model.properties(@model.repository.name)[method]
0
- _method_missing(method,args)
0
# duck type the DM::Query::Path to act like a DM::Property
Comments
No one has commented yet.