activegraph

https://github.com/neo4jrb/activegraph

Ruby

An active model wrapper for the Neo4j Graph Database for Ruby.

Neo4j::ActiveNode::HasN::ClassMethods#has_many

For defining an "has many" association on a model.  This defines a set of methods on
your model instances.  For instance, if you define the association on a Person model:


.. code-block:: ruby

  has_many :out, :vehicles, type: :has_vehicle

This would define the following methods:

**#vehicles**
  Returns a QueryProxy object.  This is an Enumerable object and thus can be iterated
  over.  It also has the ability to accept class-level methods from the Vehicle model
  (including calls to association methods)

**#vehicles=**
  Takes an array of Vehicle objects and replaces all current ``:HAS_VEHICLE`` relationships
  with new relationships refering to the specified objects

**.vehicles**
  Returns a QueryProxy object.  This would represent all ``Vehicle`` objects associated with
  either all ``Person`` nodes (if ``Person.vehicles`` is called), or all ``Vehicle`` objects
  associated with the ``Person`` nodes thus far represented in the QueryProxy chain.
  For example:

  .. code-block:: ruby

    company.people.where(age: 40).vehicles

Arguments:
  **direction:**
    **Available values:** ``:in``, ``:out``, or ``:both``.

    Refers to the relative to the model on which the association is being defined.

    Example:

    .. code-block:: ruby

      Person.has_many :out, :posts, type: :wrote

    means that a `WROTE` relationship goes from a `Person` node to a `Post` node

  **name:**
    The name of the association.  The affects the methods which are created (see above).
    The name is also used to form default assumptions about the model which is being referred to

    Example:

    .. code-block:: ruby

      Person.has_many :out, :posts, type: :wrote

    will assume a `model_class` option of ``'Post'`` unless otherwise specified

  **options:** A ``Hash`` of options.  Allowed keys are:
    *type*: The Neo4j relationship type.  This option is required unless either the
      `origin` or `rel_class` options are specified

    *origin*: The name of the association from another model which the `type` and `model_class`
      can be gathered.

      Example:

      .. code-block:: ruby

        # `model_class` of `Post` is assumed here
        Person.has_many :out, :posts, origin: :author

        Post.has_one :in, :author, type: :has_author, model_class: :Person

    *model_class*: The model class to which the association is referring.  Can be a
      Symbol/String (or an ``Array`` of same) with the name of the `ActiveNode` class,
      `false` to specify any model, or nil to specify that it should be guessed.

    *rel_class*: The ``ActiveRel`` class to use for this association.  Can be either a
      model object ``include`` ing ``ActiveRel`` or a Symbol/String (or an ``Array`` of same).
      **A Symbol or String is recommended** to avoid load-time issues

    *dependent*: Enables deletion cascading.
      **Available values:** ``:delete``, ``:delete_orphans``, ``:destroy``, ``:destroy_orphans``
      (note that the ``:destroy_orphans`` option is known to be "very metal".  Caution advised)

Source | Google | Stack overflow

Edit

git clone [email protected]:neo4jrb/activegraph.git

cd activegraph

open

Contribute

# Make a new branch

git checkout -b -your-name--update-docs-Neo4j--ActiveNode--HasN--ClassMethods-has_many-for-pr


# Commit to git

git add git commit -m "better docs for Neo4j::ActiveNode::HasN::ClassMethods#has_many"


# Open pull request

gem install hub # on a mac you can `brew install hub`

hub fork

git push <your name> -your-name--update-docs-Neo4j--ActiveNode--HasN--ClassMethods-has_many-for-pr

hub pull-request


# Celebrate!