1DBIx::Class::Helper::RoUws:e:rSuCboCnltarsisb(u3t)ed PerDlBIDxo:c:uCmleanstsa:t:iHoenlper::Row::SubClass(3)
2
3
4
6 DBIx::Class::Helper::Row::SubClass - Convenient subclassing with
7 DBIx::Class
8
10 # define parent class
11 package ParentSchema::Result::Bar;
12
13 use strict;
14 use warnings;
15
16 use parent 'DBIx::Class';
17
18 __PACKAGE__->load_components('Core');
19
20 __PACKAGE__->table('Bar');
21
22 __PACKAGE__->add_columns(qw/ id foo_id /);
23
24 __PACKAGE__->set_primary_key('id');
25
26 __PACKAGE__->belongs_to( foo => 'ParentSchema::Result::Foo', 'foo_id' );
27
28 # define subclass
29 package MySchema::Result::Bar;
30
31 use strict;
32 use warnings;
33
34 use parent 'ParentSchema::Result::Bar';
35
36 __PACKAGE__->load_components(qw{Helper::Row::SubClass Core});
37
38 __PACKAGE__->subclass;
39
40 or with DBIx::Class::Candy:
41
42 # define subclass
43 package MySchema::Result::Bar;
44
45 use DBIx::Class::Candy
46 -base => 'ParentSchema::Result::Bar',
47 -components => ['Helper::Row::SubClass'];
48
49 subclass;
50
52 This component is to allow simple subclassing of DBIx::Class Result
53 classes.
54
56 subclass
57 This is probably the method you want. You call this in your child
58 class and it imports the definitions from the parent into itself.
59
60 generate_relationships
61 This is where the cool stuff happens. This assumes that the namespace
62 is laid out in the recommended "MyApp::Schema::Result::Foo" format. If
63 the parent has "Parent::Schema::Result::Foo" related to
64 "Parent::Schema::Result::Bar", and you inherit from
65 "Parent::Schema::Result::Foo" in "MyApp::Schema::Result::Foo", you will
66 automatically get the relationship to "MyApp::Schema::Result::Bar".
67
68 set_table
69 This is a super basic method that just sets the current classes' table
70 to the parent classes' table.
71
73 If used in conjunction with DBIx::Class::Candy this component will
74 export:
75
76 join_table
77 subclass
78 generate_relationships
79 set_table
80
82 This Component is mostly aimed at those who want to subclass parts of a
83 schema, maybe for sharing a login system in a few different projects.
84 Do not confuse it with DBIx::Class::DynamicSubclass, which solves an
85 entirely different problem. DBIx::Class::DynamicSubclass is for when
86 you want to store a few very similar classes in the same table
87 (Employee, Person, Boss, etc) whereas this component is merely for
88 reusing an existing schema.
89
91 Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
92
94 This software is copyright (c) 2020 by Arthur Axel "fREW" Schmidt.
95
96 This is free software; you can redistribute it and/or modify it under
97 the same terms as the Perl 5 programming language system itself.
98
99
100
101perl v5.34.0 2021-07-D2B2Ix::Class::Helper::Row::SubClass(3)