-
Notifications
You must be signed in to change notification settings - Fork 10
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
can't find .association<< method #17
Comments
By default, CoreData returns an NSSet and not an NSArray when you are accessing a has_many relationship. Read this SO article about it: http://stackoverflow.com/a/17018816 I think in your case, you should be doing: bus = Business.current
bus.addSiteObject Site.new Optionally, you could create an NSMutableSet from the NSSet and assign that back to the property by hand: bus = Business.current
sites = NSMutableSet.setWithSet(bus.sites)
sites.addObject Site.new
bus.sites = sites |
Thanks for the quick response and SO pointer. My confusion is due to this example in your README:
Why does '<<' work here? |
Either that worked at some point and was documented, but doesn't now, or more likely never worked and was just documented incorrectly :( Sorry about the confusion, I'll turn this ticket into a PR to update the README to reflect our discussion. |
Any way we can get the readme updated with a more realistic relational example? This is tripping me up too. trying to do something like: item = WishlistItem.new(item:1234, qtyFree:1) # qtyFree is the only required attribute for WishListItem
Hostesses.shared_hostess.current_hostess.wishlist << item and getting Here's my data model: |
Oh, i also tried doing something like this as well: Hostesses.shared_hostess.current_hostess.addWishlistObject(item)
=> #<NSException:0x178b3f10> |
OK, i think I'm getting somewhere... sorry for all the messages. When I do the above, i get an (main)> Hostesses.shared_hostess.current_hostess.wishlist.allObjects
=> [#<WishlistItem catalog: nil, item: 1234, name: nil, pages: nil, price: 0.0, qtyFree: 1, qtyHalfPrice: 0, retired: nil, stopSell: nil, type: nil>] it seems like the item was inserted into the Running When I run 2014-05-15 20:29:52.726 Closer[58755:70b] persistence.rb:92:in `save!': wishlist invalid (MotionDataWrapper::RecordNotSaved)
from persistence.rb:75:in `save'
=> false any help would be appreciated! |
Looking over your posts, I'm honestly not sure what's going on. With the example core data schema shown above, I would think the following would work: h = Hostess.new
w = WishlistItem.new
h.addWishlistObject w
h.save The fact that you get a Can you post your validations you have configured in CD? The fact that |
FYI - over the weekend I tried out CDQ and ruby-xcdm and I think I may go that way instead. Still trying to weigh my options here. I really like the auto-generation of the |
I've got to assume I'm having n00b issues (since I can't imagine this not working) so patience will be appreciated.
data models:
Business has_many Sites
Site belongs_to Business
My associations are setup exactly like this example: https://github.com/sxross/motion_data_wrapper-example
Any idea why the NSSet is returned instead of an array? More importantly, why no 'sites<<' method? I don't see any such method being created in your code.
A nit: in relation/core_data.rb you have:
seems it should be:
The text was updated successfully, but these errors were encountered: