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, Class::DBI::Rela‐
21 tionship::HasMany and Class::DBI::Relationship::MightHave.
22
23 remap_arguments
24
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 recom‐
59 mended that you use this as a hashref to store any extra informa‐
60 tion your relationship needs rather than adding extra accessors, as
61 this information will all be stored in the 'meta_info'.
62
63 triggers
64
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 trig‐
73 gers that the relationship needs. This method can be omitted if there
74 are no triggers to be set up.
75
76 methods
77
78 sub methods {
79 return (
80 method1 => sub { ... },
81 method2 => sub { ... },
82 );
83 }
84
85 Subclasses may define a 'methods' method that returns a list of methods
86 to facilitate the relationship that should be created in the calling
87 Class::DBI class. This method can be omitted if there are no methods
88 to be set up.
89
90
91
92perl v5.8.8 2006-11-05 Class::DBI::Relationship(3)