[Dbix-class] Class methods on result source classes
John Napiorkowski
jjn1056 at yahoo.com
Mon Sep 3 15:51:15 GMT 2007
--- Pedro Melo <melo at simplicidade.org> wrote:
> Hi,
>
> I'm using a "fat model" approach in a small project
> and one thing
> that keeps popping up is class methods.
>
> For example, I usually have a can_edit() method in a
> base class that
> all my sources use. This allows me to do something
> like this:
>
>
>
$schema->resultset('Books')->find($id)->can_edit($current_user);
>
> The can_edit() method will receive as "self" the
> Book with the $id,
> and it will just work.
>
> But if I want to write a can_create(), I do
> something like:
>
>
$schema->resultset('Books')->->can_create($current_user);
>
> or like this
>
>
$schema->resultset('Books')->result_class->can_create($current_user);
>
> The second one is longer but easier to do because it
> doesn't require
> me to create a ResultSet class for each source.
>
> Any common, more elegant, solution to this problems?
>
> Thanks,
> --
> Pedro Melo
> Blog: http://www.simplicidade.org/notes/
> XMPP ID: melo at simplicidade.org
> Use XMPP!
Hi,
See if
"http://search.cpan.org/~ash/DBIx-Class-0.08006/lib/DBIx/Class/Manual/Cookbook.pod#Predefined_searches"
can help you. I've use this technique for anytime I
need a method against the resultset.
If you find this is helpful and discover that you need
lots of these kinds of classes, you should take a look
at:
http://search.cpan.org/~ash/DBIx-Class-0.08006/lib/DBIx/Class/Schema.pm#load_namespaces
Which is a neat way to create 'drop' points for
resultset classes. At least I think so.
--john
____________________________________________________________________________________
Luggage? GPS? Comic books?
Check out fitting gifts for grads at Yahoo! Search
http://search.yahoo.com/search?fr=oni_on_mail&p=graduation+gifts&cs=bz
More information about the DBIx-Class
mailing list