Name

Object::Relation::Meta::Class::Schema - Object::Relation database store builder

Synopsis

See Object::Relation::Meta::Class.

Description

This module is provides metadata for all Object::Relation classes while building a storage schema. Loading Object::Relation::Schema causes it to be used instead of Object::Relation::Meta::Class. This is so that extra metadata methods are available that are useful in constructing the schema, but are not otherwise useful when an application is actually in use.

At this point, those attributes tend to be database-specific. Once other types of data stores are added (XML, LDAP, etc.), other attributes may be added to allow their schemas to be built, as well.

Instance Interface

Instance Methods

parent

  my $parent = $class->parent;

Returns the Class::Meta::Class object representing the immediate parent class of the class, provided that that parent is a concrete class rather than an abstract class. Classes for which the parent is abstract will return undef.

parents

  my @parents = $class->parents;

Overrides the parents() method in Class::Meta to return only concrete parents, since abstract parents aren't really relevant for building a data store schema.

table

  my $table = $class->table;

Returns the name of the table to be used for this class in the database.

Classes with no concrete parent class will be named for the key name of the classes they represent, prepended by an underscore, such as "_party". Classes that inherit from a concrete class will be named for their inheritance relationship, such as "party_person" for the person class.

view

  my $view = $class->view;

Returns the name of the database view to be used for this class. Views, which represent a class of objects and often build up their representations from a number of different tables, shall be named for the key names of the classes they represent. Typical names include "party", "usr", "person", "contact_type", etc.

primary_key

  my $pk = $class->primary_key;

Primary key constraints are named for the class key preceded by "pk_". For example, the primary key for the "person" class shall be named "pk_person" and the primary key for the "party" class shall be named "pk_party".

foreign_key

  my $fk = $class->foreign_key;

For classes that inherit from another concrete class, their primary ID column will also be a foreign key to primary ID column in the parent class' table. This method returns the name of the foreign key constraint for such classes. The foreign key constraint name starts with "pfk_", then the key name of the parent class, then the key name of the current class, and ends with "_id".

For example, the foreign key applied to the primary key column created for the "person" class to point to the primary key for the "party" class (the class from which "person" inherits) shall be named "pfk_person_party_id", apply to the "id" column of the "party_person" table, and refer to the "id" column of the "_party" table.

If the parent() method returns a false value, this method returns undef.

table_attributes

  my @attrs = $class->table_attributes;

Returns the Object::Relation::Meta::Attribute::Schema objects for the attributes that correspond to columns in the table used for the class. Thus, it excludes attributes from concrete parent classes and from any extended classes, since they're implemented in their own tables. See parent_attributes() to get a list of the attributes of concrete parent classes and view_attributes() for a list of table attributes and extended class attributes. It also excludes the id attribute, since it just gets in the way when building schemas.

persistent_attributes

  my @attrs = $class->persistent_attributes;

Overrides the parent version to exclude the id attribute, since it just gets in the way when building schemas.

direct_attributes

  my @attrs = $class->direct_attributes;

Overrides the parent version to exclude the id attribute, since it just gets in the way when building schemas.

Instance Methods

parent_attributes

  my $attrs = $class->parent_attributes($class);

Pass the Object::Relation::Meta::Class::Schema object of a concrete parent class to get back a list of the attributes for that class. This is useful for constructing views to represent inherited classes.

build

This private method overrides the parent build() method in order to gather extra metadata information necessary for building a data store schema.

Copyright and License

Copyright (c) 2004-2006 Kineticode, Inc. <info@obj_relode.com>

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.