Inherits from: NSObject
Conforms to: NSObject
Declared in: EOAccess/EOModelGroup.h
An EOModelGroup represents an aggregation of related models (see the EOModel class specification for more information on models). When a model in the group needs to resolve a relationship to an entity in another model, it looks for that model in its group. Model groups allow applications to load entities and their properties only as they're needed, by distributing them among separate EOModels.
The default model group contains all models for an application, as well as any frameworks the application references. It is automatically created on demand. The entity name space among all of these models is global; consequently, the same entity name shouldn't appear in any two of the models. All cross-model information is represented in the models by entity name only. Binding the entity name to an actual entity is done at run-time within the EOModelGroup.
In the majority of applications, the automatic creation of the default model group is sufficient. However, your code can override this automatic creation; see "Setting Up A Model Group Programmatically" .
Accessing Models Within a Model Group
Each model lives within a group and can form connections to other models in its group. A model can find a related model using the statement:
[[self modelGroup] modelNamed:name];
A data source can locate a model using the statement:
[[EOModelGroup defaultGroup] modelNamed:name];
EOModeler puts models with identical names in separate groups to allow you to load two models with the same name at the same time.
Your EOModelGroup object should have a delegate which can influence how it finds and loads models. In addition to the delegates you assign to EOModelGroup instances, the EOModelGroup class itself can have a delegate. The class delegate implements a single method- defaultModelGroup-while the instance delegate can implement the methods defined in the EOModelGroup Delegate protocol. For more information on EOModelGroup class delegate and instance delegate methods, see the EOModelGroup Class Delegate and EOModelGroup Delegate protocol specifications, respectively. Note that the following delegate methods are set on EOModelGroup, rather than EOEntity, to provide a single point in the code where you can alter the database-to-objects mapping:
In EOModelGroup.h, EOModelGroupEOAccess defines NSString constants for the names of the notifications it posts. For more information on these notifications, see "Notifications" .
- Accessing models
- - addModelWithFile:
- - modelNamed:
- - modelNames
- - models
- - modelWithPath:
- - removeModel:
- Accessing model groups
- + defaultGroup
- + setDefaultGroup:
- + globalModelGroup
- Searching a group
- - entityNamed:
- - entityForObject:
- - entitiesWithSharedObjects
- - fetchSpecificationNamed:entityNamed:
- - storedProcedureNamed:
- Loading all of a group's objects
- - loadAllModelObjects
- Assigning a delegate
- + classDelegate
- - delegate
- + setClassDelegate:
- - setClassDelegate:
Returns the EOModelGroup's class delegate.
This delegate optionally implements the defaultModelGroup method
(see the EOModelGroup Class Delegate protocol specification
for more information).
See Also: + setClassDelegate:
Returns the default EOModelGroup. Unless you've
either specified a default model group with setDefaultGroup: or
implemented the defaultModelGroup class
delegate method to return a non
+ (EOModelGroup *)defaultGroup
nilvalue, this method is equivalent to globalModelGroup.
See Also: + classDelegate
Returns an EOModelGroup composed of all models
in the resource directory of the main bundle, as well as those in
all the bundles and frameworks loaded into the application.
+ (EOModelGroup *)globalModelGroup
See Also: + defaultGroup
Assigns anObject as
the EOModelGroup's class delegate. The class delegate is optional;
it allows you to determine the default model group (see the EOModelGroup Class Delegate protocol specification
for more information).
See Also: + classDelegate, - defaultModelGroup
Sets the default model group to group.
If you've implemented the defaultModelGroup class
delegate method to return a non
nilvalue, the delegate's return value overrides group as the default model group.
See Also: + defaultGroup, + setClassDelegate:
Adds a model to
the receiver, sets the model's
model group to the receiver, and posts EOModelAddedNotification. Raises an
exception if the receiver already contains an EOModel with the same
name as the specified model.
Creates an EOModel object with the contents
of the file identified by path, adds
the newly-created model to the receiver, and returns it. Throws
an exception if for any reason it cannot create the model from the
file specified by path. Uses the
EOModel method initWithContentsOfFile: to initialize
the new model, and adds it to the receiver.
- (EOModel *)addModelWithFile:(NSString
Returns the receiver's delegate, which is
different from the EOModelGroup's class delegate. Each EOModelGroup
object can have it's own delegate in addition to the delegate
that's assigned to the EOModelGroup class. See the EOModelGroup Delegate protocol specification
for more information.
See Also: - setClassDelegate:, + classDelegate
Returns an array of entities that have objects
to load into a shared editing context.
- (NSArray *)entitiesWithSharedObjects
Returns the EOEntity associated with object from
any of the models in the receiver that handle object, or nil if
none of the entities in the receiver handles object.
- (EOEntity *)entityForObject:(id)object
See Also: - entityForObject: (EOModel)
Searches each of the EOModels in the receiver
for the entity specified by entityName,
and returns the entity if found. Returns nil if it is unable to
find the specified entity.
- (EOEntity *)entityNamed:(NSString
See Also: - entityNamed: (EOModel)
Returns the named fetch specification from the
entity specified by entityName in
the receiving model group.
- (EOFetchSpecification *)fetchSpecificationNamed:(NSString
Sends loadAllModelObjects to
each of the receiver's EOModels, thereby loading any EOEntities, EOAttributes,
EORelationships, and EOStoredProcedures that haven't yet been
loaded from each of the EOModels in the receiver.
See Also: - loadAllModelObjects (EOModel)
Returns the EOModel named modelName if
it's part of the receiver, or nil if the receiver doesn't contain an
EOModel with the specified name.
- (EOModel *)modelNamed:(NSString
Returns an array containing the names of all
of the EOModels in the receiver, or an empty array if the receiver
contains no EOModels. The order of the model names in the array
- (NSArray *)modelNames
Returns an array containing the receiver's
EOModels, or an empty array if the receiver contains no EOModels.
The order of the models in the array isn't defined.
- (NSArray *)models
If the receiver contains an EOModel whose path
(as determined by sending path to
the EOModel object) is equal to path,
that EOModel is returned. Otherwise, returns nil. NSString's isEqual: method
is used to compare the paths, and each path is standardized (with stringByStandardizingPath) before comparison.
- (EOModel *)modelWithPath:(NSString
See Also: - path (EOModel)
Removes aModel from
the receiver, and unbinds any connections to aModel from
other EOModels in the receiver. Posts EOModelInvalidatedNotification to the
default notification center after removing aModel from
See Also: - EOModelGroup, - models
Sets the receiver's delegate to anObject.
See the EOModelGroup Delegate protocol specification
for more information.
See Also: - delegate
Returns the stored procedure in the receiving
model group having the given name.
- (EOStoredProcedure *)storedProcedureNamed:(NSString
EOModelGroup declares and posts the following notifications.
EOModelAddedNotificationPosted by an EOModelGroup when an EOModel is added to the group. This notification is sent, for instance, inside Interface Builder when the user has saved changes to a model in EOModeler and the objects in Interface Builder must be brought back in sync. The old model is flushed and receivers of the notification (like data sources) can invoke modelNamed: to re-fetch their models.
|Notification Object||The newly added model.|
EOModelInvalidatedNotificationPosted by an EOModelGroup when an EOModel is removed from the group. This notification is sent, for instance, inside Interface Builder when the user has saved changes to a model in EOModeler and the objects in Interface Builder must be brought back in sync. The old model is flushed and receivers of the notification (like data sources) can invoke modelNamed: to re-fetch their models.
|Notification Object||The invalidated model.|