1Class::DBI::RelationshiUps(e3r)Contributed Perl DocumentCaltaisosn::DBI::Relationship(3)
2
3
4
6 Class::DBI::Relationship - base class for Relationships
7
9 A Class::DBI class represents a database table. But merely being able
10 to represent single tables isn't really that useful - databases are all
11 about relationships.
12
13 So, Class::DBI provides a variety of Relationship models to represent
14 common database occurences (HasA, HasMany and MightHave), and provides
15 a way to add others.
16
18 Relationships should inherit from Class::DBI::Relationship, and provide
19 a variety of methods to represent the relationship. For examples of how
20 these are used see Class::DBI::Relationship::HasA,
21 Class::DBI::Relationship::HasMany and
22 Class::DBI::Relationship::MightHave.
23
24 remap_arguments
25 sub remap_arguments {
26 my $self = shift;
27 # process @_;
28 return ($class, accessor, $foreign_class, $args)
29 }
30
31 Subclasses should define a 'remap_arguments' method that takes the
32 arguments with which your relationship method will be called, and
33 transforms them into the structure that the Relationship modules
34 requires. If this method is not provided, then it is assumed that your
35 method will be called with these 3 arguments in this order.
36
37 This should return a list of 4 items:
38
39 class
40 The Class::DBI subclass to which this relationship applies. This
41 will be passed in to you from the caller who actually set up the
42 relationship, and is available for you to call methods on whilst
43 performing this mapping. You should almost never need to change
44 this.
45
46 This usually an entire application base class (or Class::DBI
47 itself), but could be a single class wishing to override a default
48 relationship.
49
50 accessor
51 The method in the class which will provide access to the results of
52 the relationship.
53
54 foreign_class
55 The class for the table with which the class has a relationship.
56
57 args
58 Any additional args that your relationship requires. It is
59 recommended that you use this as a hashref to store any extra
60 information your relationship needs rather than adding extra
61 accessors, as this information will all be stored in the
62 'meta_info'.
63
64 triggers
65 sub triggers {
66 return (
67 before_create => sub { ... },
68 after_create => sub { ... },
69 );
70 }
71
72 Subclasses may define a 'triggers' method that returns a list of
73 triggers that the relationship needs. This method can be omitted if
74 there are no triggers to be set up.
75
76 methods
77 sub methods {
78 return (
79 method1 => sub { ... },
80 method2 => sub { ... },
81 );
82 }
83
84 Subclasses may define a 'methods' method that returns a list of methods
85 to facilitate the relationship that should be created in the calling
86 Class::DBI class. This method can be omitted if there are no methods
87 to be set up.
88
89
90
91perl v5.30.1 2020-01-29 Class::DBI::Relationship(3)