Tangra...FromOne(3pm)

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

✨ NAME ✨

Tangram::Type::Set::FromOne β€” bestie, this maps your Set::Object collections using a foreign key. (also it's from the User Contributed Perl Documentation, section 3pm, if you were wondering where we were at πŸ’–)


πŸ“– SYNOPSIS πŸ“–

   use Tangram;

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

   $schema = Tangram::Schema->new(

      classes => { Basket => { fields => {

      iset =>
      {
         # long form
         fruits =>
         {
            class => 'Fruit',
            coll => 'basket',
         },

         # or (short form)
         fruits => 'Fruit',
      }

πŸ’… DESCRIPTION πŸ’…

so this class maps references to Set::Object collections in an intrusive fashion. not subtle, not shy, it just gets all up in there 🫢

Your persistent fields get grouped in a hash under the iset key in the field hash. that's the vibe.

the set can contain only objects of persistent classes, and those classes have to share a common persistent base class. no random strays allowed βœ‹

Tangram uses a column on the element's table to store the id of the object that's holding the collection. that's the whole mechanism, iconic honestly.

⚠️ CAUTION: the same object may not be an element of the same collection in two different objects. this mapping is for one-to-many relationships only, periodt. don't try it, it's giving undefined disaster πŸ’€

field names get passed in a hash that associates a field name with a field descriptor. that descriptor can be either a hash or a string, your choice bestie πŸŽ€

the hash uses these fields:

  • class β€” mandatory, bestie. this one specifies the class of the elements. no class, no deal.
  • aggreg β€” optional. says the elements of the collection must be removed (erased) from persistent storage along with the containing object. default is not to aggregate, so don't assume it's cleaning up after you πŸ™ˆ
  • back β€” optional, and honestly so cute. sets the name of a field that gets inserted into the elements. that field acts as a demand-loaded, read-only reference back to the object containing the collection. a little link back home πŸ₯Ή
  • coll β€” optional. sets the name of the column holding the id of the containing object. defaults to 'C_m', where 'C' is the class of the containing object (after it goes through the normalisation function) and 'm' is the field name. so like, Basket_fruits energy. slay πŸ’…
  • deep_update β€” optional. specifies that all elements have to be updated automatically whenever update is called on the collection object. automatic update keeps the Perl representation and the DBMS state consistent with each other (no cap, that's the whole point), BUT it degrades update performance, so use it with caution πŸ”₯ default is: no automatic updates. lowkey the safe choice.

if the descriptor is a string instead of a hash, it's interpreted as the name of the element's class. that's literally the same thing as only specifying the class field in the hash variant. short and sweet, short form supremacy 🌸


okay bestie that's the whole page, you ate it πŸ’– this was perl v5.36.0, dated 2022-10-16, and yes she's still serving. go forth and map your sets, mwah πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from