Instead of overriding the table() method for each persistent class, the table

name should be included in classSettings().
This commit is contained in:
Ben Simpson 2003-05-07 11:03:26 +00:00
parent 96bfe07ec9
commit 2786df46ce
4 changed files with 35 additions and 21 deletions

View file

@ -48,7 +48,8 @@ sub classSettings {
parentId => { defaultValue => 0 },
collateralFolderId => { key => 1 },
description => { quote => 1 }
}
},
table => 'collateralFolder'
}
}
@ -73,6 +74,4 @@ sub recursiveDelete {
WebGUI::Collateral->multiDelete(@collateralIds);
}
sub table { 'collateralFolder' }
1;

View file

@ -87,7 +87,8 @@ sub classSettings {
groupIdEdit => { defaultValue => 3 },
hideFromNavigation => { defaultValue => 0 },
},
useDummyRoot => 1
useDummyRoot => 1,
table => 'page'
}
}
@ -236,9 +237,5 @@ sub makeUnique {
return $url;
}
#-------------------------------------------------------------------
sub table { 'page' }
1;

View file

@ -43,17 +43,15 @@ database.
use WebGUI::Persistent;
our @ISA = qw(WebGUI::Persistent);
sub table { 'myTable' }
sub classSettings {
{
properties => {
A => { key => 1 },
B => { defaultValue => 5},
C => { quote => 1 , defaultValue => "hello world"},
D => { }
}
D => { },
},
table => 'myTable'
}
}
@ -114,6 +112,18 @@ sub classData {
This class method must be overridden to return a hash reference with one or
more of the following keys.
sub classSettings {
{
properties => {
A => { key => 1 },
B => { defaultValue => 5},
C => { quote => 1 , defaultValue => "hello world"},
D => { },
},
table => 'myTable'
}
}
=over
=item properties
@ -139,6 +149,10 @@ Should be true for fields that need to be quoted in database queries.
=back
=head2 table
This must be set to the name of the table that this class represents.
=back
=cut
@ -457,13 +471,19 @@ sub set {
=head2 table
This method must be overriden to return the name of the table modeled by this
class.
Returns the table name set in classSettings().
=cut
=cut
sub table {
WebGUI::ErrorHandler::fatalError("table() must be overridden");
my ($class) = @_;
unless ($class->classData->{table}) {
unless ($class->classSettings->{table}) {
WebGUI::ErrorHandler::fatalError("table() must be overridden");
}
$class->classData->{table} = $class->classSettings->{table};
}
return $class->classData->{table}
}
1;

View file

@ -44,9 +44,6 @@ methods), and from Tree::DAG_Node (to provide tree manipulation methods).
use WebGUI::Persistent::Tree;
our @ISA = qw(WebGUI::Persistent::Tree);
sub table { 'myTreeTable' }
sub classSettings {
{
properties => {
@ -55,7 +52,8 @@ methods), and from Tree::DAG_Node (to provide tree manipulation methods).
C => { quote => 1 , defaultValue => "hello world"},
parentId => { defaultValue => 0 },
sequenceNumber => { defaultValue => 1 }
}
},
table => 'myTreeTable'
}
}