NAME

Tangram::Array - map Perl arrays using a link table

SYNOPSIS

use Tangram;

# or
use Tangram::Core;
use Tangram::Array;

$schema = Tangram::Schema->new(

	classes => { Company => { fields => {

	array =>
	{
		# long form
		employee =>
		{
			class => 'Person',
			table => 'Company_employees',
			coll => 'company',
			item => 'employee',
			slot => 'slot'
		},

		# short form
		assets => 'Asset',
	}

DESCRIPTION

Maps references to a Perl array. The persistent fields are grouped in a hash under the array key in the field hash.

The array may contain only objects of persistent classes. These classes must have a common persistent base class.

Tangram uses a link table to save the state of the collection. The table has three columns, which contain

  • the id of the container objects

  • the id of the elements

  • the position of the element in the array

The field names are passed in a hash that associates a field name with a field descriptor. The field descriptor may be either a hash or a string. The hash uses the following fields:

  • class

  • table

  • coll

  • item

  • slot

Mandatory field class specifies the class of the elements.

Optional field table sets the name of the link table. This defaults to 'C_F', where C is the class of the containing object and F is the field name.

Optional field coll sets the name the column containing the ids of the containing objects. This defaults to 'coll'.

Optional field item sets the name the column containing the ids of the elements. This defaults to 'item'.

Optional field slot sets the name the column containing the position of the elements. This defaults to 'slot'.

If the descriptor is a string, it is interpreted as the name of the element's class. This is equivalent to specifying only the class field in the hash variant.