SYNOPSIS

   use Tangram::Core;
   use Tangram::Type/Hash/Scalar; # always

   $schema = Tangram::Schema->new(
      classes => { NaturalPerson => { fields => {

      flat_hash =>
      {
         opinions =>
         {
            table => 'NP_ops',
            key_sql => 'VARCHAR(10)',
            type => 'int',
            sql => 'NUMERIC(1)',
         },

         lucky_numbers => 'int', # use defaults
      }

DESCRIPTION

Maps references to a Perl hash. The persistent fields are grouped in a hash under the \*(C`flat_hash\*(C' key in the field hash.

The hash may contain as keys and values only 'simple' scalars like integers, strings or real numbers. It may not contain references. For hashs of objects, see Tangram::Type::Hash::FromMany and Tangram::Type::Hash::FromOne.

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

  • the id of the container object

  • the key of the element in the hash

  • the value of the element

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:

  • key_type

  • key_sql

  • type

  • sql

  • table

The optional fields \*(C`key_type\*(C' and \*(C`type\*(C' specify the key and value types of the hash. If the type is \*(C`string\*(C' Tangram quotes the values as they are passed to the database. Not specifying a \*(C`type\*(C' is exactly equivalent to specifying \*(C`string\*(C'.

Optional field \*(C`table\*(C' sets the name of the table that contains the elements. This defaults to 'C_F', where C is the class of the containing object and F is the field name.

The optional fields \*(C`key_sql\*(C' and \*(C`sql\*(C' specify the type that deploy() (see Tangram::Deploy) should use for the column containing the key and value of the hash. If this field is not present, the \s-1SQL\s0 type is derived from the \*(C`type\*(C' field: if \*(C`type\*(C' is \*(C`string\*(C' (or is absent) \s-1VARCHAR\s0(255) is used; otherwise, the \*(C`type\*(C' field is interpreted as a \s-1SQL\s0 type.

If the descriptor is a string, it is interpreted as the value of the \*(C`type\*(C' field and all the other fields take the default value.

AUTHOR

This mapping was contributed by Gabor Herr <[email protected]>