PDA

View Full Version : Core Data Application Question




EricBrian
Nov 13, 2007, 02:48 PM
So, in my quest to learn more about creating cocoa applications, I have a question about how I created the entities for an application I am trying to create as a learning exercise.

The attached image shows the 3 entities that I've created.

3 Questions:

1) So, what I am trying to do is allow a user to create a recipe that has one or more categories. And, the user also has to be able to add many ingredients to one recipe. Did I capture this correctly as shown below?

2) Now, the example I read on how to create a Core Data Application says that there should always be an inverse relationship for data integrity reasons. Is this the case?

3) And if so, I think I have satisfied that. Or?

Thanks. :)



Eraserhead
Nov 13, 2007, 02:49 PM
you have an inverse relationship there.

EricBrian
Nov 13, 2007, 02:54 PM
you have an inverse relationship there.

Thanks Eraserhead for your quick reply. I edited the above post because I was trying to get 3 answers from my original post.

Eraserhead
Nov 13, 2007, 03:02 PM
You seem to have satisfied 1) as well, I'm not sure I understand 3).

MadDoc
Nov 13, 2007, 06:14 PM
@EricBrian:

I'm new to Cocoa / ObjC programming AND keen to write a recipe management app too. What are the odds? :)

I'm just about at the stage of dabbling with Core Data (I figure it's the way to go) - in fact, I have the Apple CoreData.pdf open on my desktop as we speak!

One thing's for certain, REALbasic was a lot easier to pick up (although I appreciate it is lacking a lot compared to Cocoa).

MadDoc,

EricBrian
Nov 13, 2007, 06:25 PM
@EricBrian:

I'm new to Cocoa / ObjC programming AND keen to write a recipe management app too. What are the odds? :)

Yeah, funny that you should decide to do a recipe app, too. I am doing it because when I was wondering what to do, my mom asked me if I knew of a program that she could use. I told her that I will make it for her. :) In any case, my fav programming lang is Python, so have a guess at what lang I'll be using. :)


One thing's for certain, REALbasic was a lot easier to pick up (although I appreciate it is lacking a lot compared to Cocoa).

Yeah, VB.Net was a lot easier to pick up, too.

kainjow
Nov 13, 2007, 11:14 PM
One thing's for certain, REALbasic was a lot easier to pick up

Not so easy on the wallet though ;)

WeeBull
Nov 14, 2007, 06:42 AM
1) So, what I am trying to do is allow a user to create a recipe that has one or more categories. And, the user also has to be able to add many ingredients to one recipe. Did I capture this correctly as shown below?


Well...

You've got that a Recipe can have 1 or more categories, and that it can have 1 or more ingredients, but your inverse relationships are not "to-many" relationships so you can only have one recipe in a category, and and ingredient can only be used in one recipe.

I doubt this is what you want, so make sure all of your relationships are "to-many" (in this case)

2) Now, the example I read on how to create a Core Data Application says that there should always be an inverse relationship for data integrity reasons. Is this the case?


What a relationship allows you to say is "given A, what Bs are related?". So in your case you might say "Given a recipe, what categories are related?". The inverse of that is "Given a category, what recipes are related?" and that's also a useful question, so yes you want an inverse relationship.

There might be cases when the inverse isn't a useful question, but it's rare and I can't think of an example, so its normally good practice to have one.

Eraserhead
Nov 14, 2007, 07:11 AM
There might be cases when the inverse isn't a useful question, but it's rare and I can't think of an example, so its normally good practice to have one.

It does happen, but when you are coding you always run into situations where you need them even if you didn't realise that at the design stage.