Rose::DB::Object::Metadata::ForeignKey(3pm) | User Contributed Perl Documentation | Rose::DB::Object::Metadata::ForeignKey(3pm) |
Rose::DB::Object::Metadata::ForeignKey - Foreign key metadata.
use Rose::DB::Object::Metadata::ForeignKey; $fk = Rose::DB::Object::Metadata::ForeignKey->new(...); $fk->make_methods(...); ...
Objects of this class store and manipulate metadata for foreign keys in a database table. It stores information about which columns in the local table map to which columns in the foreign table.
This class will create methods for "the thing referenced by" the foreign key column(s). You'll still need accessor method(s) for the foreign key column(s) themselves.
Both the local table and the foreign table must have Rose::DB::Object-derived classes fronting them.
Foreign keys can represent both "one to one" and "many to one" relationships. To choose, set the relationship_type attribute to either "one to one" or "many to one". The default is "many to one".
A Rose::DB::Object::Metadata::ForeignKey-derived object is responsible for creating object methods that manipulate objects referenced by a foreign key. Each foreign key object can make zero or more methods for each available foreign key method type. A foreign key method type describes the purpose of a method. The default list of foreign key method types contains only one type:
Methods are created by calling make_methods. A list of method types can be passed to the call to make_methods. If absent, the list of method types is determined by the auto_method_types method. A list of all possible method types is available through the available_method_types method.
These methods make up the "public" interface to foreign key method creation. There are, however, several "protected" methods which are used internally to implement the methods described above. (The word "protected" is used here in a vaguely C++ sense, meaning "accessible to subclasses, but not to the public.") Subclasses will probably find it easier to override and/or call these protected methods in order to influence the behavior of the "public" method maker methods.
A Rose::DB::Object::Metadata::ForeignKey object delegates method creation to a Rose::Object::MakeMethods-derived class. Each Rose::Object::MakeMethods-derived class has its own set of method types, each of which takes it own set of arguments.
Using this system, four pieces of information are needed to create a method on behalf of a Rose::DB::Object::Metadata::ForeignKey-derived object:
This information can be organized conceptually into a "method map" that connects a foreign key method type to a method maker class and, finally, to one particular method type within that class, and its arguments.
The default method map for Rose::DB::Object::Metadata::ForeignKey is:
Each item in the map is a foreign key method type. For each foreign key method type, the method maker class, the method maker method type, and the "interesting" method maker arguments are listed, in that order.
The "..." in the method maker arguments is meant to indicate that arguments have been omitted. Arguments that are common to all foreign key method types are routinely omitted from the method map for the sake of brevity.
The purpose of documenting the method map is to answer the question, "What kind of method(s) will be created by this foreign key object for a given method type?" Given the method map, it's possible to read the documentation for each method maker class to determine how methods of the specified type behave when passed the listed arguments.
Remember, the existence and behavior of the method map is really implementation detail. A foreign key object is free to implement the public method-making interface however it wants, without regard to any conceptual or actual method map.
For the method types "get_set", "get_set_now", and "get_set_on_save", the foreign key's name is returned.
For the method types "delete_now" and "delete_on_save", the foreign key's name prefixed with "delete_" is returned.
Otherwise, undef is returned.
If any of the methods could not be created for any reason, a fatal error will occur.
These methods are not part of the public interface, but are supported for use by subclasses. Put another way, given an unknown object that "isa" Rose::DB::Object::Metadata::ForeignKey, there should be no expectation that the following methods exist. But subclasses, which know the exact class from which they inherit, are free to use these methods in order to implement the public API described above.
Returns the name of the Rose::Object::MakeMethods-derived class used to create the object method of type TYPE.
Returns the method maker method type for the foreign key method type TYPE.
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.
2020-06-21 | perl v5.30.3 |