Class-DBI-0.96 > Class::DBI::Relationship

名前

Class::DBI::Relationship - リレーションシップのベースクラス

説明

A Class::DBI class represents a database table. But merely being able to represent single tables isn't really that useful - databases are all about relationships.

Class::DBIクラスはデータベーステーブルを表す。だが単に一つひとつの テーブルを表すだけでは真に有用であるとはいえない――データベースは リレーションシップが肝心なのだから。

So, Class::DBI provides a variety of Relationship models to represent common database occurences (HasA, HasMany and MightHave), and provides a way to add others.

そこでClass::DBIは様々なリレーションシップモデルを提供し、一般的な データベースの有りよう(HasA、HasManyとMightHave)を表す。そして、 その他のリレーションシップモデルを追加する方法を提供している。

サブクラス化

Relationships should inherit from Class::DBI::Relationship, and provide a variety of methods to represent the relationship. For examples of how these are used see Class::DBI::Relationship::HasA, Class::DBI::Relationship::HasMany and Class::DBI::Relationship::MightHave.

リレーションシップはClass::DBI::Relationshipを継承するべきだ。 そしてリレーションシップを表す様々なメソッドを提供する。例えばどのように 利用されているかについては、Class::DBI::Relationship::HasA、 Class::DBI::Relationship::HasManyおよびClass::DBI::Relationship::MightHaveを 参照されたい。

remap_arguments

        sub remap_arguments { 
                my $self = shift;
                # process @_;
                return ($class, accessor, $foreign_class, $args)
        }

Subclasses should define a 'remap_arguments' method that takes the arguments with which your relationship method will be called, and transforms them into the structure that the Relationship modules requires. If this method is not provided, then it is assumed that your method will be called with these 3 arguments in this order.

サブクラスは'remap_arguments'メソッドを定義するとよい。これはあなたの リレーションシップメソッドが呼び出されるときに引数をとり、それらを Relationshipモジュールが必要とするデータ構造に変換する。このメソッドを 提供しない場合、これら3つの引数がこの順番で与えられて呼び出されるものと 仮定される。

This should return a list of 4 items:

このメソッドは4つのアイテムのリストを返す:

class

The Class::DBI subclass to which this relationship applies. This will be passed in to you from the caller who actually set up the relationship, and is available for you to call methods on whilst performing this mapping. You should almost never need to change this.

このリレーションシップが適用されるClass::DBIのサブクラス。この引数は 実際にリレーションシップを準備する呼び出し側から渡され、このマッピングを 実行するときに呼び出すために利用される。この引数を変更する必要は ほとんどないはずだ。

This usually an entire application base class (or Class::DBI itself), but could be a single class wishing to override a default relationship.

この引数は普通、完全にアプリケーションベースクラス(あるいはClass::DBIそれ自身) なのだが、デフォルトのリレーションシップをオーバーライドしたい単体クラスにも できるだろう。

accessor

The method in the class which will provide access to the results of the relationship.

リレーションシップの結果へのアクセスを提供するこのクラスのメソッド。

foreign_class

The class for the table with which the class has a relationship.

そのクラスが持つリレーションシップの対象テーブルクラス。

args

Any additional args that your relationship requires. It is recommended that you use this as a hashref to store any extra information your relationship needs rather than adding extra accessors, as this information will all be stored in the 'meta_info'.

リレーションシップが必要とする追加引数。この引数をハッシュリファレンスとして 用いることが推奨される。それにより、余計なアクセサを追加せずとも、 リレーションシップが必要とするどんな情報も保持できる。この情報は 'meta_info'に全て格納されているからだ。

triggers

        sub triggers { 
                return (
                        before_create => sub { ... },
                        after_create  => sub { ... },
                );
        }

Subclasses may define a 'triggers' method that returns a list of triggers that the relationship needs. This method can be omitted if there are no triggers to be set up.

サブクラスはリレーションシップが必要とするトリガのリストを返す 'triggers'メソッドを定義しているかもしれない。メソッドが用意され ていなければこのメソッドは無視される。

methods

        sub methods { 
                return (
                        method1 => sub { ... },
                        method2 => sub { ... },
                );
        }

Subclasses may define a 'methods' method that returns a list of methods to facilitate the relationship that should be created in the calling Class::DBI class. This method can be omitted if there are no methods to be set up.

サブクラスは、Class::DBIクラスを呼び出すときに生成されるべき リレーションシップを楽にしてくれるメソッドのリストを返す 'methods'メソッドを定義しているかもしれない。メソッドが用意され ていなければこのメソッドは無視される。