Graphics Programs Reference
In-Depth Information
a painting might be of the
Art
asset type.
BNRAssetType
will be an entity in the model
file, and each row of that table will be mapped to an Objective-C object at runtime.
Add another entity called
BNRAssetType
to your model file. Give it an attribute called
label
of type
String
. This will be the name of the category the
BNRAssetType
repres-
ents.
Figure 16.6 Create the BNRAssetType entity
Now, you need to establish relationships between
BNRAssetType
and
BNRItem
. Rela-
tionships between entities are mapped as pointers. There are two kinds of relationships:
to-many
and
to-one
. When an entity has a to-one relationship, each instance of that entity
will have a pointer to an instance in the entity it has a relationship to. For example, the
BNRItem
entity will have a to-one relationship to the
BNRAssetType
entity. Thus, a
BNRItem
instance will have a pointer to a
BNRAssetType
instance.
When an entity has a to-many relationship, each instance of that entity has a pointer to an
NSSet
. This set contains the instances of the entity that it has a relationship with. For ex-
ample, the
BNRAssetType
entity will have a to-many relationship to
BNRItem
because
many
BNRItem
s can have the same
BNRAssetType
. Thus, a
BNRAssetType
object
will have a set of all the
BNRItem
s that are its type of asset.
With these relationships, we can ask a
BNRAssetType
object for the set of
BNRItem
s
that fall into its category, and we can ask a
BNRItem
which
BNRAssetType
it falls un-
Figure 16.7 Entities in Homepwner