Tangra...omMany(3pm)
π Tangra::Type::Array::FromMany π
okay bestie, welcome to the Tangra::Type::Array::FromMany page β it lives in the User Contributed Perl Documentation section of the Tangra...omMany(3pm) manual, and it's literally the blueprint for mapping Perl arrays using a link table. yes, arrays. yes, in a database. sit down, we're doing this together π«Ά
β¨ NAME β¨
Tangram::Type::Array::FromMany β map Perl arrays using a link table. that's the whole vibe. iconic, honestly. π
πΈ SYNOPSIS πΈ
here's how you actually summon it, no cap:
use Tangram;
# or
use Tangram::Core;
use Tangram::Type::Array::FromMany;
$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',
}
see how there's a long form and a short form? one's the full main-character entrance, the other's the low-effort "just text me" version. both valid, both slay. β¨
π¦ DESCRIPTION π¦
so what this does: it maps references to a Perl array. π the persistent fields get grouped in a hash under the "array" key in the field hash. that's the spot. that's where they live.
the array may contain only objects of persistent classes, and those classes must have a common persistent base class. it's giving "we're all family here" β fr fr, no renegade plain scalars allowed π«
Tangram uses a link table to save the state of the collection. the table has three columns, and those three columns contain:
- the id of the container objects
- the id of the elements
- the position of the element in the array
three columns, one job, ate that π
π the field descriptor situation π
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 β your choice bestie, pick your fighter π
the hash uses the following fields:
- class
- aggreg
- table
- coll
- item
- slot
- deep_update
and now the breakdown of each one, because we do not gatekeep:
classβ mandatory π do not skip this one. it specifies the class of the elements.aggregβ optional. this specifies that the elements of the collection must be removed (erased) from persistent storage along with the containing object. the default is not to aggregate.tableβ optional. sets the name of the link table. this defaults to'C_F', whereCis the class of the containing object andFis the field name. so yes, it name-generates for you, the algorithm is just doing its little thing πcollβ optional. sets the name the column containing the ids of the containing objects. this defaults to'coll'.itemβ optional. sets the name the column containing the ids of the elements. this defaults to'item'.slotβ optional. sets the name the column containing the position of the elements. this defaults to'slot'.deep_updateβ optional. 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 it degrades update performance, so use it with caution π«£ the default is not to do automatic updates.
β οΈ okay real talk for a second β that deep_update one is a whole tradeoff. like, yes, consistency is cute, but bestie the performance hit is real. use it with caution, we've been warned.
π the string shortcut π
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. so assets => 'Asset' is doing the absolute most with the absolute least, and honestly? obsessed β¨
and that's the whole page, bestie. you're now certified in Tangram::Type::Array::FromMany. go forth and map your arrays. π§
sign-off tea β: this page ships with perl v5.36.0 and it's dated 2022-10-16. mwah, go be great ππ
π¦ where this page comes from
- ubuntu noble: libtangram-perl 2.12-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libtangram-perl 2.12-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libtangram-perl 2.12-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms