FAQ
Hello,

I'm very new to Catalyst, so at the moment I am playing around with some
things. I think I've got a very basic question:
I'm not sure how to pull out more complicated queries from the
controller by providing subroutines/accessors.



I created a LDAP-Model and sourced out the connection-parameters to
myapp.config

<Model::Person>
base ou=TSM,ou«C,oÿfff,cÞ
password extremlysecret
<start_tls_options>
verify none
</start_tls_options>
port 1111
start_tls 0
dn cn=readproxytsm,ou=services,oÿff,cÞ
host ldaps://ldapauth.ffff.de
</Model::Person>


Then I tested it by a controller query, which works very well:

# Then, in your controller
my $mesg = $c->model('Person')->search('(uid=lu21rue)');
my @entries = $mesg->entries;
$c->stash({
template => 'books/person.tt',
person_uri => $entries[0]->uid,
person => $entries[0],
});





But I don't wanna pollute my controllers, so I wanted to source out
complicated queries in special classes which should provide accessors.
So I extended the Model-class to use an adaptor:



package ldap::Model::Person;

use strict;
use warnings;
use base qw/Catalyst::Model::LDAP/;
use parent 'Catalyst::Model::Adaptor';


__PACKAGE__->config(
class => 'ldap::Model::Person::Utils',
args => {}
);


package ldap::Model::Person::Utils;

use Moose;
use namespace::clean -except => 'meta';
extends 'Catalyst::Model::LDAP';


sub getPerson {
my ($self, $person) = @_;

my $mesg = $self->search('(uid='.$person.')');
my @entries = $mesg->entries;

return @entries;
}


__PACKAGE__->meta->make_immutable;



But that's defnitly the wrong way, 'cause $c->model('Person') from the
controller returns a Catalyst::Model::LDAP::Connection reference.
What's the right way to pull out these queries from the controller and
store them in their own classes?

Thank u in advnace :-D

Search Discussions

  • Kevin montuori at Dec 13, 2010 at 2:45 pm

    On Mon, Dec 13, 2010 at 9:24 AM, piccard wrote:

    I'm very new to Catalyst, so at the moment I am playing around with some
    things. I think I've got a very basic question:
    I'm not sure how to pull out more complicated queries from the controller by
    providing subroutines/accessors.
    See the documentation related to the "connection_class" and
    "entry_class" configuration items. You can specify subclasses of
    Catalyst::Model::LDAP::Connection and Catalyst::Model::LDAP::Entry and
    use them exactly as you'd expect.


    k.


    --
    kevin montuori
  • Vivek Chhikara at Dec 14, 2010 at 3:27 pm
    I am new to catalyst and need guidance in fetching some data from my
    mysql db.

    I want to know how can I write below queries(1&2)

    Here is
    dummy table structure I am using.

    -------------------------------------------------
    table1
    =======
    qid
    sid status name
    __PACKAGE__->set_primary_key("qid");

    __PACKAGE__->belongs_to("queq_dump", 'MYAPP::Schema::Result::Table2,
    {qid => 'qid'});

    -------------------------------------------------

    table2
    pid eid qid name
    primary_key ==
    pid+qid+eid
    -------------------------------------------------

    QUERY 1

    =======
    select A.qid, A.name, A.name from table1 A, table2 B
    where

    A.qid = B.qid
    and A.sid = 1
    and B.pid != 2

    QUERY 2
    =======
    select
    A.qid, A.name, A.name from table1 A, table2 B
    where
    A.qid = B.qid
    and B.eid = (select min(eid) from table2 where table2.status = 1)
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20101214/7754a32e/attachment.htm
  • Hernan Lopes at Dec 14, 2010 at 3:37 pm
    Thats DBIx::Class question and not a catalyst question.
    here are dbix class docs:
    http://search.cpan.org/~frew/DBIx-Class-0.08124/everything you need is
    there. Take a look at joining at the bottom of the
    page.

    --Hernan
    On Tue, Dec 14, 2010 at 1:27 PM, Vivek Chhikara wrote:



    I am new to catalyst and need guidance in fetching some data from my mysql
    db.

    I want to know how can I write below queries(1&2)

    Here is dummy table structure I am using.
    -------------------------------------------------
    table1
    =======
    qid sid status name
    __PACKAGE__->set_primary_key("qid");
    __PACKAGE__->belongs_to("queq_dump",
    'MYAPP::Schema::Result::Table2, {qid => 'qid'});

    -------------------------------------------------
    table2
    pid eid qid name
    primary_key == pid+qid+eid
    -------------------------------------------------

    QUERY 1
    =======
    select A.qid, A.name, A.name from table1 A, table2 B
    where
    A.qid = B.qid
    and A.sid = 1
    and B.pid != 2

    QUERY 2
    =======
    select A.qid, A.name, A.name from table1 A, table2 B
    where
    A.qid = B.qid and B.eid = (select min(eid) from table2 where
    table2.status = 1)

    _______________________________________________
    List: Catalyst@lists.scsys.co.uk
    Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
    Searchable archive:
    http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
    Dev site: http://dev.catalyst.perl.org/
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20101214/289428cd/attachment.htm
  • Vivek Chhikara at Dec 14, 2010 at 3:59 pm
    Yeh this is DBIx :-) ..

    Thank you

    On Tue, 14 Dec 2010 13:37:47
    -0200, Hernan Lopes wrote:

    Thats DBIx::Class question and not a
    catalyst question.
    here are dbix class docs:
    http://search.cpan.org/~frew/DBIx-Class-0.08124/ [1] everything you need
    is there. Take a look at joining at the bottom of the
    page.

    --Hernan

    On Tue, Dec 14, 2010 at 1:27 PM, Vivek Chhikara
    wrote:

    I am new to catalyst and need guidance in fetching some data
    from my mysql db.

    I want to know how can I write below
    queries(1&2)

    Here is dummy table structure I am using.

    -------------------------------------------------
    table1
    =======
    qid
    sid status name
    __PACKAGE__->set_primary_key("qid");

    __PACKAGE__->belongs_to("queq_dump", 'MYAPP::Schema::Result::Table2,
    {qid => 'qid'});

    -------------------------------------------------

    table2
    pid eid qid name
    primary_key ==
    pid+qid+eid
    -------------------------------------------------

    QUERY 1

    =======
    select A.qid, A.name, A.name from table1 A, table2 B
    where

    A.qid = B.qid
    and A.sid = 1
    and B.pid != 2

    QUERY 2
    =======
    select
    A.qid, A.name, A.name from table1 A, table2 B
    where
    A.qid = B.qid
    and B.eid = (select min(eid) from table2 where table2.status = 1)

    _______________________________________________
    List:
    Catalyst@lists.scsys.co.uk [3]
    Listinfo:
    http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst [4]

    Searchable archive:
    http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ [5]
    Dev site:
    http://dev.catalyst.perl.org/ [6]

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedDec 13, '10 at 2:24p
activeDec 14, '10 at 3:59p
posts5
users4
websitecatalystframework.org
irc#catalyst

People

Translate

site design / logo © 2022 Grokbase