Anand
Anand

Reputation: 10400

Inverse relationship for to-many relationship

I have a requirement like below:

  1. Department -->> ( has many) employees
  2. Employee -->> (can belong to only one department) Department, no employee can exist without any department.

For setting this up, I have setup the model like

Department
    relationships
       name: employees
          destination: Employee
          optional:yes
          to-many:yes
          delete-rule:cascade
          inverse-relationship: none
Employee
    relationships
       name: department
          destination: Department
          optional:NO
          to-many:NO
          delete-rule: No action
  1. Should I create a inverse relationship anywhere in this model?
  2. Have I setup delete-rule for department relationship in Employee right?
  3. Is there anything else I should to get this model right?

Thanks

Upvotes: 0

Views: 140

Answers (1)

Abhi Beckert
Abhi Beckert

Reputation: 33339

Yes, you should almost always specify the inverse relationship according to apple's documentation. You've got the option of not doing so, but it should rarely be used.

I think there may be situations where your database can become corrupted if you don't create an inverse relationship, but I'm no expert.

Those two relationships should be inverse relationships of each other.

I'm not sure about the delete rule. Sorry.

EDIT: @jrturton's comment suggests your delete rule is fine.

Upvotes: 1

Related Questions