Core Data add relationship as unique constraint- iOS
Asked Answered
V

2

12

I'm developing an application with core data. There are many entities that uses relationships and in many of them they are the primary key.
I'm trying to use the unique constraints feature in the xcdatamodel but there is no way to compile the project.
The error that Xcode shows is:
cdtool cannot compile.

It only happens with relationships, if I add an attribute in the constraints there is no problem.

I would like to know if I'm doing something wrong or the relationship cannot be a unique constraint.

EDIT 1: relationshipsandconstraints

Voiced answered 27/7, 2016 at 7:0 Comment(5)
If possible, try to give picture of data model and relationshipsImportance
I have edited with the data model.Contrasty
still seems to happen in iOS11 :(Overstate
As far as I know you can't add relationship in constraints. Go to the entity Articulo and add a constraint there. You are adding it from BodegonRegSkivvy
constraints field must be string type. So it can't be relationship. I know I am very late in replying. But still posting if some still have any confusion about it.Spinks
A
1
`Articulo` is an entity, it's not the property you can set constraints. You should select `Ariculo` and add constraint `ariculoId`(this is the proper of Articulo) to it to make `Ariculo` is unique. In your diagram, `arculo_id` is the relationship. You may not set constraint on it possible.

Think about if the relationship is oneToMany, what you should do?

EDIT:

Tested on Xcode 15, no errors, BUT it doesn't work.

See the image below. bar is the to-one relation:

enter image description here

Here is the result.

enter image description here

Then we try to set Bar's name as the constraint: Still not work!

enter image description here

So far, seems To-One has no uniqeness feature.

Aerometry answered 6/2 at 8:53 Comment(0)
R
0

This can also happen when in the constraints you put the property of the object and not the object! For example if you put entity.attribute

Restriction answered 10/1, 2021 at 0:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.