[Dbix-class] To find or search?

Dermot paikkos at googlemail.com
Mon Sep 8 14:29:25 BST 2008


Hi,

I think this is a bit of a lame question but I'll ask anyway.

I have a (SQLite3) table of files. There are 4 fields as set out below.

id INTEGER PRIMARY KEY,
sub_id INTEGER,
users_id INTEGER,
path VARCHAR(50) UNIQUE ON CONFLICT IGNORE

I have set-up beongs_to relationships between tb.files and tb.subs and
tb.users. All is well and I can recall the list of files belonging to
a user like this

my $rs = $c->model('MyApp::Files')->find({'users_id' => $id}) # Yes
it's a Cat app.

or a submission like this

my $rs = $c->model('MyApp::Files')->find({'sub_id' => $id})

However, each submission can have up to 8 different file types (jpg,
txt,...). Say I want to know if a submission has a  jpeg in it. I
could loop through the resultset and search for /jpg$/ but I suspect
that not how a pro would do it. I suspect the answer would be to 1)
Store the type as a ENUM field (not SQLite) or 2) use some additional
criteria for the find query or  3) use search instead.

Any tips/thoghts?
TIA,
Dp.



More information about the DBIx-Class mailing list