[Dbix-class] To find or search?

Wade.Stuart at fallon.com Wade.Stuart at fallon.com
Mon Sep 8 17:23:04 BST 2008



Dermot <paikkos at googlemail.com> wrote on 09/08/2008 08:29:25 AM:

> 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
filetype VARCHAR(3)

You don't really _need_ enum,  just fake it.
Split and lc the extension out during insert.  Limit allowed types via
logic before insert time. Then either find just the types you want via
query or code around the types that you treat via logic.





>
> 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.
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive:
http://www.grokbase.com/group/dbix-class@lists.rawmode.org




More information about the DBIx-Class mailing list