Tangra...FromOne(3pm)
β¨ 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_fruitsenergy. slay πdeep_updateβ optional. specifies that all elements have to be updated automatically wheneverupdateis 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
- 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