---
name: "Rose::DB::Object::Metadata::Relationship::OneToMany"
section: "3pm"
platform: "linux"
package: "librose-db-object-perl"
version: "1:0.820-2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Rose::DB::Object::Metadata::Relationship::OneToMany"
---

# Rose::DB::Object::Metadata::Relationship::OneToMany(3pm)

One to many table relationship metadata object.

## NAME

Rose::DB::Object::Metadata::Relationship::OneToMany - One to many table relationship metadata object.

## SYNOPSIS

```
  use Rose::DB::Object::Metadata::Relationship::OneToMany;
  $rel = Rose::DB::Object::Metadata::Relationship::OneToMany->new(...);
  $rel->make_methods(...);
  ...
```

## DESCRIPTION

Objects of this class store and manipulate metadata for relationships in which a single row from one table refers to multiple rows in another table.

This class inherits from Rose::DB::Object::Metadata::Relationship. Inherited methods that are not overridden will not be documented a second time here.  See the Rose::DB::Object::Metadata::Relationship documentation for more information.

## METHOD MAP

- "count"

  Rose::DB::Object::MakeMethods::Generic, objects\_by\_key, `"interface => 'count'"` ...

- "find"

  Rose::DB::Object::MakeMethods::Generic, objects\_by\_key, `"interface => 'find'"` ...

- "iterator"

  Rose::DB::Object::MakeMethods::Generic, objects\_by\_key, `"interface => 'iterator'"` ...

- "get\_set"

  Rose::DB::Object::MakeMethods::Generic, objects\_by\_key,  `"interface => 'get_set'"` ...

- "get\_set\_now"

  Rose::DB::Object::MakeMethods::Generic, objects\_by\_key, `"interface => 'get_set_now'"` ...

- "get\_set\_on\_save"

  Rose::DB::Object::MakeMethods::Generic, objects\_by\_key, `"interface => 'get_set_on_save'"` ...

- "add\_now"

  Rose::DB::Object::MakeMethods::Generic, objects\_by\_key, `"interface => 'add_now'"` ...

- "add\_on\_save"

  Rose::DB::Object::MakeMethods::Generic, objects\_by\_key, `"interface => 'add_on_save'"` ...

See the Rose::DB::Object::Metadata::Relationship documentation for an explanation of this method map.

## CLASS METHODS

- **default\_auto\_method\_types \[TYPES\]**

  Get or set the default list of auto\_method\_types.  TYPES should be a list of relationship method types.  Returns the list of default relationship method types (in list context) or a reference to an array of the default relationship method types (in scalar context).  The default list contains "find", "get\_set\_on\_save", and "add\_on\_save".

## OBJECT METHODS

- **build\_method\_name\_for\_type TYPE**

  Return a method name for the relationship method type TYPE.

  For the method types "get\_set", "get\_set\_now", and "get\_set\_on\_save", the relationship's name is returned.

  For the method types "add\_now" and "add\_on\_save", the relationship's name prefixed with "add\_" is returned.

  For the method type "find", the relationship's name prefixed with "find\_" is returned.

  For the method type "count", the relationship's name suffixed with "\_count" is returned.

  For the method type "iterator", the relationship's name suffixed with "\_iterator" is returned.

  Otherwise, undef is returned.

- **is\_singular**

  Returns false.

- **manager\_class \[CLASS\]**

  Get or set the name of the Rose::DB::Object::Manager-derived class used to fetch objects.  The make\_methods method will use Rose::DB::Object::Manager if this value is left undefined.

  **Note:** when the name of a relationship that has `"manager_args"` is used in a Rose::DB::Object::Manager with\_objects or require\_objects parameter value, *only* the sort\_by argument will be copied from `"manager_args"` and incorporated into the query.

- **manager\_method \[METHOD\]**

  Get or set the name of the manager\_class class method to call when fetching objects.  The make\_methods method will use get\_objects if this value is left undefined.

- **manager\_count\_method \[METHOD\]**

  Get or set the name of the manager\_class class method to call when counting objects.  The make\_methods method will use get\_objects\_count if this value is left undefined.

- **manager\_iterator\_method \[METHOD\]**

  Get or set the name of the manager\_class class method to call when creating an iterator.  The make\_methods method will use get\_objects\_iterator if this value is left undefined.

- **manager\_args \[HASHREF\]**

  Get or set a reference to a hash of name/value arguments to pass to the manager\_method when fetching objects.  For example, this can be used to enforce a particular sort order for objects fetched via this relationship.  For example:

  ```
    Product->meta->add_relationship
    (
      code_names =>
      {
        type         => 'one to many',
        class        => 'CodeName',
        column_map   => { id => 'product_id' },
        manager_args =>
        {
          sort_by => CodeName->meta->table . '.name',
        },
      },
    );
  ```

  This would ensure that a `"Product"`'s `"code_names()"` are listed in alphabetical order.  Note that the "name" column is prefixed by the name of the table fronted by the `"CodeName"` class.  This is important because several tables may have a column named "name."  If this relationship is used to form a JOIN in a query along with one of those tables, then the "name" column will be ambiguous.  Adding a table name prefix disambiguates the column name.

  Also note that the table name is not hard-coded.  Instead, it is fetched from the Rose::DB::Object-derived class that fronts the table.  This is more verbose, but is a much better choice than including the literal table name when it comes to long-term maintenance of the code.

  See the documentation for Rose::DB::Object::Manager's get\_objects method for a full list of valid arguments for use with the `"manager_args"` parameter, but remember that you can define your own custom manager\_class and thus can also define what kinds of arguments `"manager_args"` will accept.

- **map\_column LOCAL \[, FOREIGN\]**

  If passed a local column name LOCAL, return the corresponding column name in the foreign table.  If passed both a local column name LOCAL and a foreign column name FOREIGN, set the local/foreign mapping and return the foreign column name.

- **column\_map \[HASH \| HASHREF\]**

  Get or set a reference to a hash that maps local column names to foreign column names.

- **query\_args \[ARRAYREF\]**

  Get or set a reference to an array of query arguments to add to the query passed to the manager\_method when fetching objects.

- **type**

  Returns "one to many".

## AUTHOR

John C. Siracusa (siracusa@gmail.com)

## LICENSE

Copyright (c) 2010 by John C. Siracusa.  All rights reserved.  This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
