Skip to content

Commit

Permalink
Stash work on returning Scope::Relationship as a models relationship.
Browse files Browse the repository at this point in the history
  • Loading branch information
alloy committed Aug 12, 2012
1 parent ee7595c commit eeb315d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/managed_object.rb
Expand Up @@ -35,7 +35,7 @@ def inherited(klass)


def entityDescription def entityDescription
@entityDescription ||= EntityDescription.new.tap do |ed| @entityDescription ||= EntityDescription.new.tap do |ed|
ed.name = ed.managedObjectClassName = self.name ed.name = ed.managedObjectClassName = name
end end
end end


Expand Down Expand Up @@ -86,13 +86,16 @@ def method_missing(method, *args, &block)
end end
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) def writeAttribute(key, value)
key = key.to_s key = key.to_s
willChangeValueForKey(key) willChangeValueForKey(key)
setPrimitiveValue(value, forKey:key) setPrimitiveValue(value, forKey:key)
didChangeValueForKey(key) didChangeValueForKey(key)
end end

end end


end end
12 changes: 12 additions & 0 deletions spec/managed_object_spec.rb
Expand Up @@ -48,6 +48,18 @@ module MotionData
Author.edgars.target.should == Author Author.edgars.target.should == Author
Author.edgars.predicate.predicateFormat.should == 'name == "edgar"' Author.edgars.predicate.predicateFormat.should == 'name == "edgar"'
end 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
end end


Expand Down

0 comments on commit eeb315d

Please sign in to comment.