Relationship
-
Welcome to YapDatabase!
The project page has a wealth of documentation if you have any questions. https://github.com/yapstudios/YapDatabase
If you’re new to the project you may want to visit the wiki. https://github.com/yapstudios/YapDatabase/wiki
The YapDatabaseRelationship extension allow you to create relationships between objects, and configure automatic deletion rules.
For tons of information about this extension, see the wiki article: https://github.com/yapstudios/YapDatabase/wiki/Relationships
See moreDeclaration
Objective-C
@interface YapDatabaseRelationship : YapDatabaseExtension
Swift
class YapDatabaseRelationship : YapDatabaseExtension
-
This class allows for various customizations to the YapDatabaseRelationship extension.
See moreDeclaration
Objective-C
@interface YapDatabaseRelationshipOptions : NSObject <NSCopying>
Swift
class YapDatabaseRelationshipOptions : NSObject, NSCopying
-
Welcome to YapDatabase!
The project page has a wealth of documentation if you have any questions. https://github.com/yapstudios/YapDatabase
If you’re new to the project you may want to visit the wiki. https://github.com/yapstudios/YapDatabase/wiki
The YapDatabaseRelationship extension allow you to create relationships between objects, and configure automatic deletion rules.
For tons of information about this extension, see the wiki article: https://github.com/yapstudios/YapDatabase/wiki/Relationships
See moreDeclaration
Objective-C
@interface YapDatabaseRelationshipConnection : YapDatabaseExtensionConnection
Swift
class YapDatabaseRelationshipConnection : YapDatabaseExtensionConnection
-
Welcome to YapDatabase!
The project page has a wealth of documentation if you have any questions. https://github.com/yapstudios/YapDatabase
If you’re new to the project you may want to visit the wiki. https://github.com/yapstudios/YapDatabase/wiki
The YapDatabaseRelationship extension allow you to create relationships between objects, and configure automatic deletion rules.
For tons of information about this extension, see the wiki article: https://github.com/yapstudios/YapDatabase/wiki/Relationships
See moreDeclaration
Objective-C
@interface YapDatabaseRelationshipTransaction : YapDatabaseExtensionTransaction
Swift
class YapDatabaseRelationshipTransaction : YapDatabaseExtensionTransaction
-
Undocumented
See moreDeclaration
Objective-C
@interface YapDatabaseRelationshipEdge : NSObject <NSCopying> /** * Returns an edge with the given name, destination & nodeDeleteRules. * * This method is suitable for use with the YapDatabaseRelationshipNode protocol. * When using this protocol, the source object is directly queried by the YapDatabaseRelationship extension. * Thus the extension already knows what the source node is, * and so the source node information (sourceKey & sourceCollection) doesn't need to be explicitly set on the edge. * * This method is not suitable for use with manual edge management. * When manually adding an edge, you must fully specify the source node. */ + (instancetype)edgeWithName:(NSString *)name destinationKey:(NSString *)destinationKey collection:(nullable NSString *)destinationCollection nodeDeleteRules:(YDB_NodeDeleteRules)rules; /** * Returns an edge with the given name, destinationFileURL & nodeDeleteRules. * * When using a destinationFileURL, only a subset of the nodeDeleteRules apply. * Specifically only the following work: * - YDB_DeleteDestinationIfSourceDeleted * - YDB_DeleteDestinationIfAllSourcesDeleted * * This method is suitable for use with the YapDatabaseRelationshipNode protocol. * When using this protocol, the source object is directly queried by the YapDatabaseRelationship extension. * Thus the extension already knows what the source node is, * and so the source node information (sourceKey & sourceCollection) doesn't need to be explicitly set on the edge. * * This method is not suitable for use with manual edge management. * When directly adding an edge, you must fully specify the source node. */ + (instancetype)edgeWithName:(NSString *)name destinationFileURL:(NSURL *)destinationFileURL nodeDeleteRules:(YDB_NodeDeleteRules)rules; /** * Returns a fully specified edge. * * This method is suitable for use with manual edge management. * * If you're using the YapDatabaseRelationshipNode protocol, then you can use the shorter version of this method * which doesn't specify the source node. This is because the source node is implied with the * YapDatabaseRelationshipNode protocol, and thus doesn't need to be explicitly specified in the edge. */ + (instancetype)edgeWithName:(NSString *)name sourceKey:(NSString *)sourceKey collection:(nullable NSString *)sourceCollection destinationKey:(NSString *)destinationKey collection:(nullable NSString *)destinationCollection nodeDeleteRules:(YDB_NodeDeleteRules)rules; /** * Returns a fully specified edge. * * When using a destinationFileURL, only a subset of the nodeDeleteRules apply. * Specifically only the following work: * - YDB_DeleteDestinationIfSourceDeleted * - YDB_DeleteDestinationIfAllSourcesDeleted * * This method is suitable for use with manual edge management. * * If you're using the YapDatabaseRelationshipNode protocol, then you can use the shorter version of this method * which doesn't specify the source node. This is because the source node is implied with the * YapDatabaseRelationshipNode protocol, and thus doesn't need to be explicitly specified in the edge. */ + (instancetype)edgeWithName:(NSString *)name sourceKey:(NSString *)sourceKey collection:(nullable NSString *)sourceCollection destinationFileURL:(NSURL *)destinationFileURL nodeDeleteRules:(YDB_NodeDeleteRules)rules; #pragma mark Init /** * For documentation @see edgeWithName:destinationKey:collection:nodeDeleteRules: */ - (id)initWithName:(NSString *)name destinationKey:(NSString *)key collection:(nullable NSString *)collection nodeDeleteRules:(YDB_NodeDeleteRules)rules; /** * For documentation @see edgeWithName:destinationFileURL:nodeDeleteRules: */ - (id)initWithName:(NSString *)name destinationFileURL:(NSURL *)destinationFileURL nodeDeleteRules:(YDB_NodeDeleteRules)rules; /** * For documentation @see edgeWithName:sourceKey:collection:destinationKey:collection:nodeDeleteRules: */ - (id)initWithName:(NSString *)name sourceKey:(NSString *)sourceKey collection:(nullable NSString *)sourceCollection destinationKey:(NSString *)destinationKey collection:(nullable NSString *)destinationCollection nodeDeleteRules:(YDB_NodeDeleteRules)rules; /** * For documentation @see edgeWithName:sourceKey:collection:destinationFileURL:nodeDeleteRules: */ - (id)initWithName:(NSString *)name sourceKey:(NSString *)sourceKey collection:(nullable NSString *)sourceCollection destinationFileURL:(NSURL *)destinationFileURL nodeDeleteRules:(YDB_NodeDeleteRules)rules; #pragma mark Properties @property (nonatomic, copy, readonly) NSString *name; @property (nonatomic, copy, readonly) NSString *sourceKey; @property (nonatomic, copy, readonly) NSString *sourceCollection; @property (nonatomic, copy, readonly) NSString *destinationKey; @property (nonatomic, copy, readonly) NSString *destinationCollection; @property (nonatomic, copy, readonly) NSURL *destinationFileURL; @property (nonatomic, assign, readonly) YDB_NodeDeleteRules nodeDeleteRules; /** * NO if the edge was created via the YapDatabaseRelationshipNode protocol. * YES if the edge was created via "manual edge management" methods. */ @property (nonatomic, assign, readonly) BOOL isManualEdge; @end
Swift
class YapDatabaseRelationshipEdge : NSObject, NSCopying
-
There are 2 techniques you may use to add edges to the relationship graph:
- Use the YapDatabaseRelationshipNode protocol
- Manually manage the edges by adding / removing them yourself
You are welcome to use either technique. In fact you can use them both simultaneously. Which you choose may simply be whichever works best depending on the situation.
The YapDatabaseRelationshipNode protocol works quite simply:
Any object that is stored in the database may optionally implement this protocol in order to specify a list of relationships that apply to it. The object just needs to: 1.) Add the YapDatabaseRelationshipNode protocol to its declared list of protocols (in header file) 2.) Implement the yapDatabaseRelationshipEdges method
When the object is inserted or updated in the database, the YapDatabaseRelationshipExtension will automatically invoke the yapDatabaseRelationshipEdges method to get the list of edges. It then inserts the list of edges into the database (if object was inserted), or updates the previously inserted list (if object was updated).
Typically this protocol is convenient to use if:
- Your objects already contain identifiers that can be used to create the edges you desire
You’d like to be able to delete objects in the database by simply setting identifier properties to nil
See
YapDatabaseRelationshipEdge
Declaration
Objective-C
@protocol YapDatabaseRelationshipNode
Swift
protocol YapDatabaseRelationshipNode