[Dbix-class] Extending 'find' to include constant value for search query

Jon Schutz jon+dbix at youramigo.com
Fri Jun 22 00:07:52 GMT 2007


On Fri, 2007-06-22 at 08:42 +1000, Charlie Garrison wrote:
> Good morning,

In Australia.

> For one of my classes I want to extend the 'find' method so that 
> only records belonging to current user will be found. I could 
> use 'search' and compose the query, but I would prefer to keep 
> semantics of 'find' (cleaner code and all that).
> 
> I have tried overriding 'find' in the specific class, but it's 
> not getting called. I'm still wrapping my head around 
> differences in schema, result_source, result_set, row, etc. and 
> which methods each uses. I'm not sure where to put the 
> overriding methods for each of those.
> 
> So, first my question is, what is the best way to extend find so 
> that I can restrict records using an additional (constant) value 
> in the query? And if I should just override 'find', where do I 
> put my 'find' method?

find is a ResultSet method; you need to create a ResultSet class that
inherits from DBIx::Class::ResultSet, put your find in there (and
probably search_rs too), and direct your schema to use that class by
adding 

__PACKAGE__->resultset_class(...)

into your schema (table declaration) class.

-- 

Jon



More information about the Dbix-class mailing list