NAME

Rose::DB::Object::Metadata::ForeignKey - Foreign key metadata.

SYNOPSIS

  use Rose::DB::Object::Metadata::ForeignKey;

  $fk = Rose::DB::Object::Metadata::ForeignKey->new(...);
  $fk->make_methods(...);
  ...

DESCRIPTION

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.

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

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.

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:

get

Rose::DB::Object::MakeMethods::Generic, object_by_key, ...

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. If there are no "interesting" method maker arguments, then "..." may appear by itself, as shown above.

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.

CLASS METHODS

default_auto_method_types [TYPES]

Get or set the default list of auto_method_types. TYPES should 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 only the "get" foreign key method type.

OBJECT METHODS

available_method_types

Returns the full list of foreign key method types supported by this class.

auto_method_types [TYPES]

Get or set the list of foreign key method types that are automatically created when make_methods is called without an explicit list of foreign key method types. The default list is determined by the default_auto_method_types class method.

build_method_name_for_type TYPE

Return a method name for the foreign key method type TYPE. The default implementation returns the foreign key's name for the foreign key method type "get", and undef otherwise.

class [CLASS]

Get or set the class name of the Rose::DB::Object-derived object that encapsulates rows from the table referenced by the foreign key column(s).

key_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.

key_columns [HASH | HASHREF]

Get or set a reference to a hash that maps local column names to foreign column names in the table referenced by the foreign key.

make_methods PARAMS

Create object method used to manipulate object referenced by the foreign key. PARAMS are name/value pairs. Valid PARAMS are:

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 by auto_method_types.

If any of the methods could not be created for any reason, a fatal error will occur.

name [NAME]

Get or set the name of the foreign key. This name must be unique among all other foreign keys for a given Rose::DB::Object-derived class.

share_db [BOOL]

Get or set the boolean flag that determines whether the db attribute of the current object is shared with the foreign object to be fetched. The default value is true.

type

Returns "foreign key".

PROTECTED API

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.

method_maker_arguments TYPE

Returns a hash (in list context) or reference to a hash (in scalar context) of name/value arguments that will be passed to the method_maker_class when making the foreign key method type TYPE.

method_maker_class TYPE [, CLASS]

If CLASS is passed, the name of the Rose::Object::MakeMethods-derived class used to create the object method of type TYPE is set to CLASS.

Returns the name of the Rose::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@mindspring.com)

COPYRIGHT

Copyright (c) 2005 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.