0

I need some advice on how to create a coredata model that has Departments, Groups and People.

I have this working using an XML file, but I'd like to make this a proper SQLite DB.

A subset of the XML file is below..

The rules are each Dept can have multiple Groups and each group can have multiple people. Once again, I would appreciate any advice..

(Apologies for the long code post)

    <key>itemChildren</key>

        <dict>
            <key>itemChildren</key>

                <dict>
                    <key>itemChildren</key>

                        <dict>
                            <key>itemTitle</key>
                            <string>Person1</string>
                            <key>itemSubTitle</key>
                            <string>Person1Detail</string>
                        </dict>
                        <dict>
                            <key>itemTitle</key>
                            <string>Person2</string>
                        </dict>
                        <dict>
                        Person x........
                        </dict>
                        <dict>
                            <key>itemTitle</key>
                            <string>Infinitive</string>
                        </dict>

                    <key>itemTitle</key>
                    <string>Group1</string>
                    <key>itemSubTitle</key>
                    <string>Group1 Detail</string>
                </dict>
                <dict>
                    <key>itemChildren</key>

                        <dict>
                            <key>itemTitle</key>
                            <string>Person1</string>
                            <key>itemSubTitle</key>
                            <string>Person1Detail</string>
                        </dict>
                        <dict>
                            <key>itemTitle</key>
                            <string>Person2</string>
                        </dict>
                                            </array>
                    <key>itemTitle</key>
                    <string>Group2</string>
                    <key>itemSubTitle</key>
                    <string>Group2 Detail</string>
                </dict>
                <dict>
                    <key>itemChildren</key>

                        <key>itemTitle</key>
                            <string>Person1</string>
                            <key>itemSubTitle</key>
                            <string>Person1Detail</string>
                        <dict>
                            <key>itemTitle</key>
                            <string>Person2</string>
                        </dict>
                        <dict>
                            <key>itemTitle</key>
                            <string>Person3</string>
                        </dict>
                                    </array>
                    <key>itemTitle</key>
                    <string>Groupx</string>
                    <key>itemSubTitle</key>
                    <string>Groupx Detail</string>

                 ........

                </dict>

            <key>itemTitle</key>
            <string>Dept1</string>
            <key>itemSubTitle</key>
            <string>Dept1Detail</string>
        </dict>
        <dict>
            <key>itemChildren</key>

                <dict>
                    <key>itemChildren</key>
                    <array>
                        <dict>
                            <key>itemTitle</key>
                            <string>Person1</string>
                            <key>itemSubTitle</key>
                            <string>Person1Detail</string>
                .....
            <key>itemTitle</key>
            <string>Dept2</string>
            <key>itemSubTitle</key>
            <string>Dept2Detail</string>
        </dict>
        ........
            <key>itemTitle</key>
            <string>Dept3</string>
            <key>itemSubTitle</key>
            <string>Dept3Detail</string>
        </dict>

</dict>
MPelletier
  • 16,256
  • 15
  • 86
  • 137
ICL1901
  • 7,632
  • 14
  • 90
  • 138

2 Answers2

1

Unless I'm missing something, at least conceptually your database schema should be pretty simple.

I would start with the main entities required for your model: Person, Group and Department. They can each have their own individual properties as per normal.

Once you have the entities and properties created, you need to establish the relationships between them.

Based on what you said this is how I suggest you approach it, including the respective reverse relationships:

Person<<------>>Group (many-to-many) meaning one Person can be in many Groups(assumption?) and one Group can have many Person instances

Person<<------->Department (many-to-one) meaning one Person can be in one Department and one department can have many 'persons'

Group<<------->Department (many-to-one) or (many-to-many) if you want to allow groups to be part of many departments.

Rog
  • 18,602
  • 6
  • 76
  • 97
  • Hi Rog, thanks a lot for looking at this. I am going to try your model and get back to you here. I'm fine at developing with mySQL, but the graphical model makes me overcomplicate things.. Again, many thanks. – ICL1901 Feb 21 '11 at 01:31
  • @David yeah it can take a bit to get used to it but once you figured it all out it is actually pretty easy, good luck! – Rog Feb 21 '11 at 01:37
  • Rog, just to let you know - your idea stimulated my thinking, and with a couple of tweaks, it works! Many thanks - I really appreciate your advice.. – ICL1901 Feb 22 '11 at 04:04
  • Cool feel free to post your solution here for myself and others to see as well :) – Rog Feb 22 '11 at 20:17
0

I apologize for the delay in responding. Life happened.. What I came up with was a db with two tables - for argument, verbs and persons.

The schema looks like this:

core data schema

It's not as elegant as I would like as there is repetitive persons, but, it seems to work.

Again, sorry for the delay.

David

ICL1901
  • 7,632
  • 14
  • 90
  • 138