Tangra...FromOne(3pm)

πŸ“¦
version 2.12 Β· 3 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Tangra...FromOne β€” the Tangram::Type::Array::FromOne bestie guide (3pm) πŸ’–

okay so. bestie. you wanna map Perl arrays with a foreign key? this is THE module for you. no cap. it lives in the Tangram::Type::Array::FromOne era of the Tangram universe and it's here to make your intrusive array mapping dreams come true. πŸ¦‹


✨ NAME ✨

Tangram::Type::Array::FromOne β€” map Perl arrays using a foreign key. that's literally the whole vibe. πŸ’…


🌸 SYNOPSIS 🌸

use Tangram;

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

$schema = Tangram::Schema->new(

   classes => { Agenda => { fields => {

   iarray =>
   {
      # long form
      entries =>
      {
         class => 'Entry',
         coll => 'agenda',
      },

      # or (short form)
      entries => 'Entry',
   }

look at that. two ways to say the same thing. long form girlies and short form girlies, we support both. 🫢


πŸ‘‘ DESCRIPTION πŸ‘‘

This class maps references to a Perl array in an intrusive fashion. (not intrusive like your ex, intrusive like database-intrusive, it's fine, it's fine.) The persistent fields get grouped up in a hash under the iarray key in the field hash.

The array may contain only objects of persistent classes. and those classes? they all gotta share a common persistent base class. no random strays allowed. πŸ’€

Tangram uses two columns on the element's table to store:

  • the id of the object containing the collection
  • the position of the element in the collection
⚠️ CAUTION bestie: the same object may not be an element of the same collection, in two different objects. read that again. This mapping may be used only for one-to-many relationships. that's the rule, periodt. 🚨

🧚 the field descriptor tea

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
  • aggreg
  • back
  • coll
  • slot
  • deep_update

πŸ’œ all about those fields

  • Mandatory field class β€” specifies the class of the elements. you literally cannot skip this one, it's the main character. πŸ‘‘
  • Optional field aggreg β€” says that the elements of the collection must be removed (erased) from persistent storage along with the containing object. The default is not to aggregate. so by default they survive without their parent, dramatic but valid. πŸŽ€
  • Optional field back β€” sets the name of a field that gets inserted in the elements. That field acts as a demand-loaded, read-only reference to the object containing the collection. it's giving "look back at your parent" energy. ✨
  • Optional field coll β€” sets the name the column containing the id of the containing object. This defaults to C_m, where C is the class of the containing object, and m is the field name. memorise the pattern, it'll come up again. πŸ“
  • Optional field slot β€” sets the name the column containing the id of the containing object. This defaults to C_m_slot, where C is the class of the containing object, and m is the field name. same pattern, extra _slot sprinkle. 🌈
πŸ“Œ The C in C_m and C_m_slot are passed through the schema normalisation function before being combined into a column name. so don't hardcode your assumptions, the schema is doing its own little transformation routine. πŸ’«
  • Optional field deep_update β€” specifies that all elements have to be updated automatically when update is called on the collection object. Automatic update ensures consistency between the Perl representation and the DBMS state, but degrades update performance, so use it with caution. The default is not to do automatic updates. performance girlies, tread lightly. 😭

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. short form supremacy, honestly. πŸ”₯


🌟 cute sign-off 🌟

this lil page came from perl v5.36.0, dated 2022-10-16, and it's part of the User Contributed Perl Documentation for Tangra...FromOne(3pm). thanks for reading bestie, go build something iconic πŸ’–βœ¨πŸ‘‘

πŸ“¦ where this page comes from