Help language development. Donate to The Perl Foundation

ORM::ActiveRecord cpan:GDONALD last updated on 2019-10-24

t/004-model-has-many-through.t6
use v6.d;
use lib 'lib';
use ORM::ActiveRecord::Model;
use Test;

class Subscription {...}

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;
  }
}

plan 1;

%*ENV<DISABLE-SQL-LOG> = True;

my $user = User.create({fname => 'Greg'});
my $magazine = Magazine.create({title => 'Mad'});
Subscription.create({:$user, :$magazine});

ok $user.magazines.first == $magazine;

Subscription.destroy-all;
Magazine.destroy-all;
User.destroy-all;