UA-17470720-3

Jump to content


Photo
- - - - -

Relationships between two tables


  • Please log in to reply
4 replies to this topic

#1 Vince

Vince

    Jr. Member

  • STV 4.0 Std
  • PipPip
  • 23 posts
Reputation: 0
Neutral

Posted 08 April 2014 - 12:27 PM

Hello

 

I'm new to Sensible Cocoa but find it already now very powerful. I managed to make my first project with three tables and their relationships without problems, however I bumped into a problem which I tried to solve but can't find any solution.

 

Assumption: I have two tables: recipe and Aroma (ingredient) which are related with 1:Many.

 

Problem:

 

I manage to add multiple aroma (ingredients) to my recipe (with SCPropertyTypeArrayOfObjects and SCArrayOfObjectsAttributes), but always need to re-enter my ingredients separately rather than to be able and choose from already existing ones.

 

 

//Create Recipe Definition
    SCEntityDefinition *recipeDef = [SCEntityDefinition definitionWithEntityName:@"Recipes" managedObjectContext:context propertyNamesString:@"Recipe:(name,desc,pg,vg,h2o); Aroma:(r2a); Category: (r2c)"];
//Create the Aroma Definition
SCEntityDefinition *aromaDef = [SCEntityDefinition definitionWithEntityName:@"Aromas" managedObjectContext:context propertyNamesString:@"name;make;desc;pg;type"];
 
//Create Relation to Aroma
    SCPropertyDefinition *aromaRelDef = [recipeDef propertyDefinitionWithName:@"r2a"];
    aromaRelDef.title = @"Aromas";
    aromaRelDef.type = SCPropertyTypeArrayOfObjects;
    aromaRelDef.attributes = [SCArrayOfObjectsAttributes attributesWithObjectDefinition:aromaDef allowAddingItems:YES allowDeletingItems:YES allowMovingItems:YES];
 

 

If I use SCPropertyTypeSelection to retrieve Ingredients instead, I can fill a NSArray with NSStrings which I retrieve through a normal Core Data Request, but loose the ability to add new Ingredients through the Framework

 

Summary:

I would like to retrieve a list of already existing ingredients and also have the ability to add new ones, all via the framework

 

Has anyone and advice on how I can achieve this with SC? or maybe a snippet of code for demonstration?

 

Thanks and best regards

 

Vince

 

PS: in the screenshot attached, the ingredients are represented with aromas

Attached Files


Edited by ibesuf, 08 April 2014 - 12:30 PM.


#2 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 09 April 2014 - 10:08 AM

Hi Vince,

 

Your use case seems to be identical to the Task-Category use case we have in our "Core Data App" sample. In the Core Data sample app, you're able to select already existing categories from the CategoryEntity table (with the option to add new ones right from the selection screen). Please check it out and let me know if that's what you're looking for.



#3 Vince

Vince

    Jr. Member

  • STV 4.0 Std
  • PipPip
  • 23 posts
Reputation: 0
Neutral

Posted 10 April 2014 - 02:12 AM

Hi Vince,

 

Your use case seems to be identical to the Task-Category use case we have in our "Core Data App" sample. In the Core Data sample app, you're able to select already existing categories from the CategoryEntity table (with the option to add new ones right from the selection screen). Please check it out and let me know if that's what you're looking for.

 

Thank you very much for the hint, indeed it covers exactly what I want. will go through the code and figure it out... great support thanks!



#4 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 515 posts
  • LocationAustralia
Reputation: 168
Popular

Posted 13 January 2016 - 09:42 PM

hmm.. just what I was looking for.. but now all the samples are just IB created code.. there is no REAL code samples anymore :(


  • Dave Guerin likes this

P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.


#5 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 14 January 2016 - 08:31 AM

Hey Ozie,

 

If you're referring to the STV 3.0 samples, they can still be downloaded here: http://sensiblecocoa...y/1-stv-30-pro/


  • ozie likes this




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users