1 package FS::pkg_referral;
2 use base qw( FS::Record );
5 use FS::Record qw( dbh );
9 FS::pkg_referral - Object methods for pkg_referral records
15 $record = new FS::pkg_referral \%hash;
16 $record = new FS::pkg_referral { 'column' => 'value' };
18 $error = $record->insert;
20 $error = $new_record->replace($old_record);
22 $error = $record->delete;
24 $error = $record->check;
28 An FS::pkg_referral object represents the association of an advertising source
29 with a specific customer package (purchase). FS::pkg_referral inherits from
30 FS::Record. The following fields are currently supported:
34 =item pkgrefnum - primary key
36 =item pkgnum - Customer package. See L<FS::cust_pkg>
38 =item refnum - Advertising source. See L<FS::part_referral>
48 Creates a new record. To add the record to the database, see L<"insert">.
50 Note that this stores the hash reference, not a distinct copy of the hash it
51 points to. You can ask the object for a copy with the I<hash> method.
55 # the new method can be inherited from FS::Record, if a table method is defined
57 sub table { 'pkg_referral'; }
61 Adds this record to the database. If there is an error, returns the error,
62 otherwise returns false.
66 # the insert method can be inherited from FS::Record
70 Delete this record from the database.
74 # the delete method can be inherited from FS::Record
76 =item replace OLD_RECORD
78 Replaces the OLD_RECORD with this one in the database. If there is an error,
79 returns the error, otherwise returns false.
83 # the replace method can be inherited from FS::Record
87 Checks all fields to make sure this is a valid record. If there is
88 an error, returns the error, otherwise returns false. Called by the insert
93 # the check method should currently be supplied - FS::Record contains some
94 # data checking routines
100 $self->ut_numbern('pkgrefnum')
101 || $self->ut_foreign_key('pkgnum', 'cust_pkg', 'pkgnum' )
102 || $self->ut_foreign_key('refnum', 'part_referral', 'refnum' )
104 return $error if $error;
109 sub _upgrade_schema {
110 my ($class, %opts) = @_;
113 DELETE FROM pkg_referral WHERE NOT EXISTS
114 ( SELECT 1 FROM cust_pkg WHERE cust_pkg.pkgnum = pkg_referral.pkgnum )
117 my $sth = dbh->prepare($sql) or die dbh->errstr;
118 $sth->execute or die $sth->errstr;
126 Multiple pkg_referral records for a single package (configured off by default)
131 L<FS::part_referral>, L<FS::cust_pkg>, L<FS::Record>, schema.html from the