module ActiveFedora::Associations::ClassMethods

def belongs_to(name, options = {})

belongs_to :author, class_name: "Person", predicate: OurVocab.authorOf
belongs_to :firm, predicate: OurVocab.clientOf
Option examples:

if the real class name is Person, you'll have to specify it with this option.
from the association name. So has_one :author will by default be linked to the Author class, but
Specify the class name of the association. Use it only if that name can't be inferred
[:class_name]
the association predicate to use when storing the association +REQUIRED+
[:predicate]

=== Options

The declaration can also include an options hash to specialize the behavior of the association.
* Post#author=(author)
* Post#author (similar to Author.find(author_id))
A Post class declares belongs_to :author, which will add:

=== Example

belongs_to :author would add among others author.nil?.)
(+association+ is replaced with the symbol passed as the first argument, so

Assigns the associate object, extracts the primary key, and sets it as the foreign key.
[association=(associate)]
Returns the associated object. +nil+ is returned if none is found.
[association()]

this object holds an id:
Methods will be added for retrieval and query for a single associated object, for which

if this class contains the foreign key.
Specifies a one-to-one association with another class. This method should only be used
def belongs_to(name, options = {})
  Builder::BelongsTo.build(self, name, options)
  Builder::SingularProperty.build(self, name, options)
end

def contains(name, options = {}, &block)

Other tags:
    Yield: - block executed by some types of child resources

Options Hash: (**options)
  • :autocreate (Boolean) -- Always create this datastream on new objects
  • :url (String) --
  • :class_name (Class) -- The class that will represent this child, should extend ``ActiveFedora::File''

Parameters:
  • options (Hash) --
  • name (String) -- the handle to refer to this child as
def contains(name, options = {}, &block)
  options[:block] = block if block
  raise ArgumentError, "You must provide a name (dsid) for the datastream" unless name
  Associations::Builder::Contains.build(self, name.to_sym, options)
end

def directly_contains(name, options={})

Options Hash: (**options)
  • :is_member_of_relation (RDF::URI) -- the rdf predicate to use for the ldp:isMemberOfRelation
  • :has_member_relation (RDF::URI) -- the rdf predicate to use for the ldp:hasMemberRelation
  • :class_name (String) -- The name of the class that will represent the contained resources

Parameters:
  • options (Hash) --
  • name (String) -- the handle to refer to this child as
def directly_contains(name, options={})
  Builder::DirectlyContains.build(self, name, { class_name: 'ActiveFedora::File' }.merge(options))
end

def directly_contains_one(name, options={})

def directly_contains_one(name, options={})
  Builder::DirectlyContainsOne.build(self, name, { class_name: 'ActiveFedora::File' }.merge(options))
end

def has_and_belongs_to_many(name, options = {})

has_and_belongs_to_many :topics, predicate: RDF::FOAF.isPrimaryTopicOf, inverse_of: :is_topic_of
has_and_belongs_to_many :nations, class_name: "Country", predicate: OurVocab.isCitizenOf
has_and_belongs_to_many :projects, predicate: OurVocab.worksOn
Option examples:

Specify the predicate to use when storing the relationship on the foreign object. If it is not provided, the relationship will not set the foriegn association.
[:inverse_of]
REQUIRED Specify the predicate to use when storing the relationship.
[:predicate]
Project class, but if the real class name is SuperProject, you'll have to specify it with this option.
from the association name. So has_and_belongs_to_many :projects will by default be linked to the
Specify the class name of the association. Use it only if that name can't be inferred
[:class_name]

=== Options

The declaration may include an options hash to specialize the behavior of the association.
* Developer#projects.exists?(...)
* Developer#projects.find(id)
* Developer#projects.size
* Developer#projects.empty?
* Developer#projects.clear
* Developer#project_ids=
* Developer#project_ids
* Developer#projects=
* Developer#projects.delete
* Developer#projects<<
* Developer#projects
A Developer class declares has_and_belongs_to_many :projects, which will add:

=== Example

has_and_belongs_to_many :categories would add among others categories.empty?.)
(+collection+ is replaced with the symbol passed as the first argument, so

Returns the number of associated objects.
[collection.size]
Returns +true+ if there are no associated objects.
[collection.empty?]
Removes every object from the collection. This does not destroy the objects.
[collection.clear]
Replace the collection by the objects identified by the primary keys in +ids+.
[collection_singular_ids=ids]
Returns an array of the associated objects' ids.
[collection_singular_ids]
Replaces the collection's content by deleting and adding objects as appropriate.
[collection=objects]
This does not destroy the objects.
Removes one or more objects from the collection by removing their associations from the join table.
[collection.delete(object, ...)]
parent object.
Note that this operation instantly fires update sql without waiting for the save or update call on the
(collection.push and collection.concat are aliases to this method).
Adds one or more objects to the collection by creating associations in the join table
[collection<<(object, ...)]
An empty array is returned if none are found.
Returns an array of all the associated objects.
[collection(force_reload = false)]

Adds the following methods for retrieval and query:

Specifies a many-to-many relationship with another class. The relatioship is written to both classes simultaneously.
def has_and_belongs_to_many(name, options = {})
  Builder::HasAndBelongsToMany.build(self, name, options)
  Builder::Property.build(self, name, options.slice(:class_name, :predicate))
end

def has_many(name, options={})

def has_many(name, options={})
  Builder::HasMany.build(self, name, options)
end

def indirectly_contains(name, options={})

Options Hash: (**options)
  • :foreign_key (Symbol) -- property that points at the remote resource
  • :through (String) -- name of a class to represent the interstitial node
  • :inserted_content_relation (RDF::URI) -- the rdf predicate to use for the ldp:insertedContentRelation
  • :is_member_of_relation (RDF::URI) -- the rdf predicate to use for the ldp:isMemberOfRelation
  • :has_member_relation (RDF::URI) -- the rdf predicate to use for the ldp:hasMemberRelation
  • :class_name (String) -- The name of the class that will represent the contained resources

Parameters:
  • options (Hash) --
  • name (String) -- the handle to refer to this child as
def indirectly_contains(name, options={})
  Builder::IndirectlyContains.build(self, name, options)
end