Rose::DB::Object::Metadata::Relationship::OneToMany(3pm) | User Contributed Perl Documentation | Rose::DB::Object::Metadata::Relationship::OneToMany(3pm) |
Rose::DB::Object::Metadata::Relationship::OneToMany - One to many table relationship metadata object.
use Rose::DB::Object::Metadata::Relationship::OneToMany; $rel = Rose::DB::Object::Metadata::Relationship::OneToMany->new(...); $rel->make_methods(...); ...
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.
See the Rose::DB::Object::Metadata::Relationship documentation for an explanation of this method map.
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.
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.
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.
John C. Siracusa (siracusa@gmail.com)
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.
2022-10-14 | perl v5.34.0 |