[Dbix-class] Searching based on a Result Class Method
Hetényi Csaba
csabiwork at tata.hu
Tue Mar 23 20:06:41 GMT 2010
Dear Members
I have an other beginner question.
I followed the Catalyst tutorial:
http://search.cpan.org/~hkclark/Catalyst-Manual-5.8004/lib/Catalyst/Manual/=
Tutorial/04_BasicCRUD.pod
which describe, how to add own "Result Class Methods" to a result class =
below the:
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum: ....
line.
It is works, this added data can be used in template to print, but i =
don't know how to search based on it.
An example:
I have a table, which holds user informations, "born" date among other =
things.
I added a Result Class Method to get the user's age based on table =
column: "born"
Here is a cut with relevant sections:
.
.
.
"born",
{
data_type =3D> "date",
default_value =3D> "'2000-01-01'::date",
is_nullable =3D> 1,
size =3D> 4,
},
# Created by DBIx::Class::Schema::Loader v0.04006 @ 2010-03-10 15:38:32
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:dZDZBfpShIvfiiRiqCVN1Q
sub age {
my ($self) =3D @_;
my $dt =3D DateTime->now;
my $born =3D DateTime->new( year =3D> $self->born->year(),
month =3D> $self->born->month(),
day =3D> $self->born->day(),
);
my $dur =3D $dt->subtract_datetime($born);
return ($dur->years);
}
.
.
.
If i would like to search by age, it not works, because it says:
|"DBI Exception: DBD::Pg::st execute failed: ERROR: column "age" does not =
exist..."
The search code in controller:
my $search_clause =3D {
age =3D> 15,
};
my $rs =3D $c->model('DB::Users')->search(
$search_clause,
);
Thank you in advance!
Csabi
|
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20100323/d06=
7ae87/attachment.htm
More information about the DBIx-Class
mailing list