ORM::ActiveRecord now has support for has-many through relationships.
For example, a user has access to magazines through the subscriptions relationship:
class Subscription {...} # stub
class User is Model {
submethod BUILD {
self.has-many: subscriptions => class => Subscription;
self.has-many: magazines => through => :subscriptions;
}
}
class Magazine is Model {}
class Subscription is Model {
submethod BUILD {
self.belongs-to: user => class => User;
self.belongs-to: magazine => class => Magazine;
}
}
my $user = User.create({fname => 'Greg'});
my $magazine = Magazine.create({title => 'Mad'});
Subscription.create({:$user, :$magazine});
say $user.magazines.first == $magazine;
Page Updates |
---|
IPv4 Subnet Calculator |
Factorio on systemd |
Apache Bench load testing |
Console::Blackjack |
RetroPie Arcade |
Recent Articles |
---|
Install xfce4 on Debian |
Console Blackjack in Perl |
Selenium::WebDriver::Error::UnknownError |
Game of Life in C++ using the SDL2 |
PigPen (dots and boxes) in C++ using the SDL2 |
Copyright © 2005 - 2021
GregDonald.com · Contact · Nautical War · CRM12
All Rights Reserved