Rose::...ignKey(3pm)
π NAME π
Rose::DB::Object::Metadata::ForeignKey(3pm) β Foreign key metadata. User Contributed Perl Documentation, if you were curious, bestie. β¨
β¨ SYNOPSIS β¨
use Rose::DB::Object::Metadata::ForeignKey;
$fk = Rose::DB::Object::Metadata::ForeignKey->new(...);
$fk->make_methods(...);
...
π DESCRIPTION π
okay so picture this, bestie: objects of this class are the little metadata goblins that store and manipulate metadata for foreign keys in a database table. They keep track of which columns in the local table map to which columns in the foreign table. iykyk.
This class will create methods for "the thing referenced by" the foreign key column(s). Important: you'll still need accessor method(s) for the foreign key column(s) themselves. Don't forget those.
Both the local table and the foreign table must have Rose::DB::Object-derived classes fronting them. No cap, both sides need their class representation.
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". Slay.
π οΈ MAKING METHODS π οΈ
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:
"get_set"β a method that returns the object referenced by the foreign key.
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. Iconic.
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 its 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:
- The foreign key method type (e.g.,
"get_set") - The method maker class (e.g.,
Rose::DB::Object::MakeMethods::Generic) - The method maker method type (e.g.,
object_by_key) - The method maker arguments (e.g.,
"interface => 'get_set'")
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. It's giving flowchart energy, lowkey.
The default method map for Rose::DB::Object::Metadata::ForeignKey is:
"get_set"βRose::DB::Object::MakeMethods::Generic,object_by_key,"interface => 'get_set'"..."get_set_now"βRose::DB::Object::MakeMethods::Generic,object_by_key,"interface => 'get_set_now'"..."get_set_on_save"βRose::DB::Object::MakeMethods::Generic,object_by_key,"interface => 'get_set_on_save'"..."delete_now"βRose::DB::Object::MakeMethods::Generic,object_by_key,"interface => 'delete_now'"..."delete_on_save"βRose::DB::Object::MakeMethods::Generic,object_by_key,"interface => 'delete_on_save'"...
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. periodt.
π CLASS METHODS π
default_auto_method_types [TYPES]β grab or set the default list ofauto_method_types.TYPESshould be a list of foreign key method types. Returns the list of default foreign key method types (in list context) or a reference to an array of the default foreign key method types (in scalar context). The default list contains the"get_set_on_save"and"delete_on_save"foreign key method types.
π OBJECT METHODS π
available_method_typesβ returns the full list of foreign key method types supported by this class. No gatekeeping.auto_method_types [TYPES]β grab or set the list of foreign key method types that are automatically created whenmake_methodsis called without an explicit list of foreign key method types. The default list is determined by thedefault_auto_method_typesclass method.build_method_name_for_type TYPEβ return a method name for the foreign key method typeTYPE. The default implementation returns the following:- 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,
undefis returned.
- For the method types
class [CLASS]β grab or set the class name of theRose::DB::Object-derived object that encapsulates rows from the table referenced by the foreign key column(s). Main character class energy.column_map [HASH | HASHREF]β this is an alias for thekey_columnsmethod.key_column LOCAL [, FOREIGN]β if passed a local column nameLOCAL, return the corresponding column name in the foreign table. If passed both a local column nameLOCALand a foreign column nameFOREIGN, set the local/foreign mapping and return the foreign column name. Mapping time, bestie.key_columns [ HASH | HASHREF ]β grab or set a hash that maps local column names to foreign column names in the table referenced by the foreign key. Returns a reference to a hash in scalar context, or a list of key/value pairs in list context.make_methods PARAMSβ create object method used to manipulate object referenced by the foreign key. Any applicable column triggers are also added.PARAMSare name/value pairs. ValidPARAMSare:"preserve_existing BOOL"β boolean flag that indicates whether or not to preserve existing methods in the case of a name conflict."replace_existing BOOL"β boolean flag that indicates whether or not to replace existing methods in the case of a name conflict."target_class CLASS"β the class in which to make the method(s). If omitted, it defaults to the calling class."types ARRAYREF"β a reference to an array of foreign key method types to be created. If omitted, it defaults to the list of foreign key method types returned byauto_method_types.
If any of the methods could not be created for any reason, a fatal error will occur. π
methods MAPβ set the list ofauto_method_typesand method names all at once.MAPshould be a reference to a hash whose keys are method types and whose values are eitherundefor method names. If a value isundef, then the method name for that method type will be generated by callingbuild_method_name_for_type|/build_method_name_for_type, as usual. Otherwise, the specified method name will be used.method_name TYPE [, NAME]β grab or set the name of the relationship method of typeTYPE.method_types [TYPES]β this method is an alias for theauto_method_typesmethod.name [NAME]β grab or set the name of the foreign key. This name must be unique among all other foreign keys for a givenRose::DB::Object-derived class. No duplicates, bestie.referential_integrity [BOOL]β grab or set the boolean value that determines what happens when the local key columns have defined values, but the object they point to is not found. If true, a fatal error will occur when the methods that fetch objects through this foreign key are called. If false, then the methods will simply returnundef. The default is true. β οΈrel_type [TYPE]β this method is an alias for therelationship_typemethod described below.relationship_type [TYPE]β grab or set the relationship type represented by this foreign key. Valid values forTYPEare"one to one"and"many to one".share_db [BOOL]β grab or set the boolean flag that determines whether thedbattribute of the current object is shared with the foreign object to be fetched. The default value is true.soft [BOOL]β this method is the mirror image of thereferential_integritymethod. Passing a true is the same thing as settingreferential_integrityto false, and vice versa. Similarly, the return value is the logical negation ofreferential_integrity.typeβ returns"foreign key".with_column_triggers [BOOL]β grab or set a boolean value that indicates whether or not triggers should be added to the key columns in an attempt to keep foreign objects and foreign key columns in sync. Defaults to false.
π‘οΈ PROTECTED API π‘οΈ
Okay so these methods are not part of the public interface, but they are supported for use by subclasses. Put another way: if you've got some unknown object that isa Rose::DB::Object::Metadata::ForeignKey, there should be no expectation that the methods below exist. But subclasses β which know the exact class they inherit from β are free to use these methods to implement the public API described above. It's giving backstage pass, not public main character energy. π
method_maker_arguments TYPEβ returns a hash (in list context) or a reference to a hash (in scalar context) of name/value arguments that will be passed to themethod_maker_classwhen making the foreign key method type TYPE. πmethod_maker_class TYPE [, CLASS]β if CLASS is passed, the name of theRose::Object::MakeMethods-derived class used to create the object method of type TYPE is set to CLASS. Returns the name of theRose::Object::MakeMethods-derived class used to create the object method of type TYPE. β¨method_maker_type TYPE [, NAME]β if NAME is passed, the name of the method maker method type for the foreign key method type TYPE is set to NAME. Returns the method maker method type for the foreign key method type TYPE. π¦
π AUTHOR π
John C. Siracusa (siracusa@gmail.com) β iconic, no cap. π
π 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. π«Ά
And that's the whole vibe check, bestie β the footer on this Rose::...ignKey(3pm) page says perl v5.40.1 and is dated 2025-08-21, so shoutout to the source/version for keeping it real. bye and slay your subclassing adventures π
β¨πΈ
π¦ where this page comes from
- ubuntu resolute: librose-db-object-perl 1:0.822-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: librose-db-object-perl 1:0.822-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms