Permalink
Browse files

Stash work on returning Scope::Relationship as a models relationship.

  • Loading branch information...
1 parent ee7595c commit eeb315d58ff84d66b6c53fc53f5a75d8a8e0132b @alloy committed Aug 12, 2012
Showing with 17 additions and 2 deletions.
  1. +5 −2 app/managed_object.rb
  2. +12 −0 spec/managed_object_spec.rb
View
@@ -35,7 +35,7 @@ def inherited(klass)
def entityDescription
@entityDescription ||= EntityDescription.new.tap do |ed|
- ed.name = ed.managedObjectClassName = self.name
+ ed.name = ed.managedObjectClassName = name
end
end
@@ -86,13 +86,16 @@ def method_missing(method, *args, &block)
end
end
+ def relationship(name)
+ Scope::Relationship.alloc.initWithTarget(send(name), relationshipName:name, owner:self, ownerClass:self.class.entityDescription.klass)
+ end
+
def writeAttribute(key, value)
key = key.to_s
willChangeValueForKey(key)
setPrimitiveValue(value, forKey:key)
didChangeValueForKey(key)
end
-
end
end
@@ -48,6 +48,18 @@ module MotionData
Author.edgars.target.should == Author
Author.edgars.predicate.predicateFormat.should == 'name == "edgar"'
end
+
+ it "returns a Scope::Relationship instead of the normal Core Data set" do
+ author = Author.new
+ author.relationship(:articles).should.be.instance_of Scope::Relationship
+ author.relationship(:articles).owner.should == author
+ author.relationship(:articles).ownerClass.should == Author
+ author.relationship(:articles).to_a.should == []
+
+ article1 = author.relationship(:articles).new(:title => 'article1')
+ article2 = author.relationship(:articles).new(:title => 'article2')
+ author.relationship(:articles).withTitles.to_a.should == [article1, article2]
+ end
end
end

0 comments on commit eeb315d

Please sign in to comment.