Giter Club home page Giter Club logo

Comments (6)

nonamelive avatar nonamelive commented on August 18, 2024

call [[NSManagedObjectContext defaultContext] save];

from magicalrecord.

brewpoo avatar brewpoo commented on August 18, 2024

I know I can always grab the managed object context and save. Doing this feels contrary to the whole point of this type of library, which in a lot of ways is trying to hide the verbosity of the Core Data API. Does it make more sense to perform a performSaveDataOperationWithBlock?

from magicalrecord.

casademora avatar casademora commented on August 18, 2024

Or, you can use the one in your new entity:

MyEntity *m = [MyEntitty createEntity];
[m.managedObjectContext save];

Remember, Core Data is an object graph, and is a little different from other "ORM"s. The Managed Object Context manages saves, not the entities themselves.

from magicalrecord.

brewpoo avatar brewpoo commented on August 18, 2024

@casademora That makes sense. I guess I need to get used to Core Data, spent to much time with RoR...

from magicalrecord.

casademora avatar casademora commented on August 18, 2024

The performSaveOperationWithBlock is an attempt to hide the nasty setup require when saving stuff to another context, and then syncing it up with the main context. This method is also used when performing saves in the background.

I have resisted putting a save method on the entity objects themselves because it'll never be saving only that object...since saves are always performed on the context containing many entities, you could also be persisting your deletes, updates and insert for other changes.

That said, I also tried to name this library to reflect the subset of the Active Record pattern that applies, namely the fetching part. I do plan, however, to change the name of the library in the near future so that there is less confusion with the Active Record pattern.

from magicalrecord.

brewpoo avatar brewpoo commented on August 18, 2024

Yes, it would be misleading to have an instance method on an entity for save or commit. In that light it makes more sense to use the [[NSManagedObjectContext defaultContext] save] call as it clearly shows that the action will save the entire context. Makes no difference in effect but shows the devs not just the intent but what will actually happen.

from magicalrecord.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.