Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting to-many relationships with a CDQTargetedQuery or Array #118

Open
markrickert opened this issue Aug 23, 2015 · 1 comment
Open

Setting to-many relationships with a CDQTargetedQuery or Array #118

markrickert opened this issue Aug 23, 2015 · 1 comment

Comments

@markrickert
Copy link
Member

I ran into a problem where I'm having to set a to-many relationship with the following code:

new_things = Thing.where(:id).in([1, 2, 3, 4, 5]).array
my_object.things = NSSet.setWithArray(new_things)

The code above works.

This throws an error:

new_things = Thing.where(:id).in([1, 2, 3, 4, 5])
my_object.things = new_things

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unacceptable type of value for to-many relationship: property = "things"; desired type = NSSet; given type = CDQTargetedQuery; value = #CDQ::CDQTargetedQuery:0x11a11c860.'

Got the same error with a different type when calling .array on the query

Ideally, CDQ would recognize that I'm trying to set a to-many relationship with a query or an array and automatically turn it into an NSSet for me.

@kemiller
Copy link
Contributor

It may not be possible to detect this automatically because of the way NSManagedObjects work. We might be able to exploit RubyMotion's translation of thing=() into setThing(), but I'm not sure if it will work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants