Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Users

Can't get value from model

 

 

Catalyst users RSS feed   Index | Next | Previous | View Threaded


ksmclane at us

Jun 13, 2012, 1:54 PM

Post #1 of 5 (416 views)
Permalink
Can't get value from model

I am trying to get the value from a model call into a variable so I can
use it for creating a DB record. I have tried multiple ways and cannot get
the value to return. Here is my current attempt:

my $dept = $c->model('ORANGES::Departments')->search_rs({'department_code'
=> $departmentcode}, {
columns => ['department_id'] });

This returns "1".

I tried this:

my $dept = $c->model('ORANGES::Departments')->search_rs({'department_code'
=> $departmentcode}, {
columns => ['department_id'] })->single;

and got a hash reference. I know I am missing something very simple. If I
was putting this into the stash I know I could access the value, but I am
at a loss as to how to get to it inside my code.


lenjaffe at jaffesystems

Jun 13, 2012, 2:02 PM

Post #2 of 5 (392 views)
Permalink
Re: Can't get value from model [In reply to]

On Wed, Jun 13, 2012 at 4:54 PM, Kenneth S Mclane <ksmclane [at] us>wrote:

> I am trying to get the value from a model call into a variable so I can
> use it for creating a DB record. I have tried multiple ways and cannot get
> the value to return. Here is my current attempt:
>
> my $dept = $c->model('ORANGES::Departments')->search_rs({'department_code'
> => $departmentcode}, {
> columns => ['department_id'] })->single;


search_rs() returns a ResultSet, not the rows.. Try using search() instead.
L.

--
lenjaffe [at] jaffesystems 614-404-4214 www.volunteerable.net
Proprietor: http://www.theycomewithcheese.com/ - An Homage to Fromage
Greenbar <http://www.greenbartraining.org/>: Grubmaster: 2012-2009, Grub
Asst: 2008, Trained: 2007.


davewood at gmx

Jun 13, 2012, 2:15 PM

Post #3 of 5 (396 views)
Permalink
Re: Can't get value from model [In reply to]

Hi Kenneth,

that's a DBIC question


anyways, what is the output of ...

if ( $dept ) {
warn "REF: " . ref $dept . " DEPT_ID: " . $dept->department_id;
} else {
warn "No dept found";
}

... after your query?

On 13 June 2012 22:54, Kenneth S Mclane <ksmclane [at] us> wrote:
> I am trying to get the value from a model call into a variable so I can use
> it for creating a DB record. I have tried multiple ways and cannot get the
> value to return. Here is my current attempt:
>
> my $dept = $c->model('ORANGES::Departments')->search_rs({'department_code'
> => $departmentcode}, {
>                 columns => ['department_id'] });
>
> This returns "1".
>
> I tried this:
>
> my $dept = $c->model('ORANGES::Departments')->search_rs({'department_code'
> => $departmentcode}, {
>                 columns => ['department_id'] })->single;
>
> and got a hash reference. I know I am missing something very simple. If I
> was putting this into the stash I know I could access the value, but I am at
> a loss as to how to get to it inside my code.
>
>
> _______________________________________________
> List: Catalyst [at] lists
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
> Dev site: http://dev.catalyst.perl.org/
>

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


ksmclane at us

Jun 13, 2012, 2:34 PM

Post #4 of 5 (394 views)
Permalink
Re: Can't get value from model [In reply to]

David Schmidt <davewood [at] gmx> wrote on 06/13/2012 04:15:57 PM:

> From:
>
> David Schmidt <davewood [at] gmx>
>
> To:
>
> The elegant MVC web framework <catalyst [at] lists>
>
> Date:
>
> 06/13/2012 04:16 PM
>
> Subject:
>
> Re: [Catalyst] Can't get value from model
>
> Hi Kenneth,
>
> that's a DBIC question
>
>
> anyways, what is the output of ...
>
> if ( $dept ) {
> warn "REF: " . ref $dept . " DEPT_ID: " . $dept->department_id;
> } else {
> warn "No dept found";
> }
>
> ... after your query?
>
> On 13 June 2012 22:54, Kenneth S Mclane <ksmclane [at] us> wrote:
> > I am trying to get the value from a model call into a variable so I
can use
> > it for creating a DB record. I have tried multiple ways and cannot get
the
> > value to return. Here is my current attempt:
> >
> > my $dept =
$c->model('ORANGES::Departments')->search_rs({'department_code'
> > => $departmentcode}, {
> > columns => ['department_id'] });
> >
> > This returns "1".
> >
> > I tried this:
> >
> > my $dept =
$c->model('ORANGES::Departments')->search_rs({'department_code'
> > => $departmentcode}, {
> > columns => ['department_id'] })->single;
> >
> > and got a hash reference. I know I am missing something very simple.
If I
> > was putting this into the stash I know I could access the value, but I
am at
> > a loss as to how to get to it inside my code.
> >
> >
[error] Caught exception in dbms::Controller::Account->add "Can't locate
object method "department_id" via package "DBIx::Class::ResultSet" at
/home/ksmclane/catalyst/dbms/script/../lib/dbms/Controller/Account.pm line
49."


davewood at gmx

Jun 13, 2012, 2:51 PM

Post #5 of 5 (396 views)
Permalink
Re: Can't get value from model [In reply to]

On 13 June 2012 23:34, Kenneth S Mclane <ksmclane [at] us> wrote:
> David Schmidt <davewood [at] gmx> wrote on 06/13/2012 04:15:57 PM:
>
>> From:
>>
>> David Schmidt <davewood [at] gmx>
>>
>> To:
>>
>> The elegant MVC web framework <catalyst [at] lists>
>>
>> Date:
>>
>> 06/13/2012 04:16 PM
>>
>> Subject:
>>
>> Re: [Catalyst] Can't get value from model
>>
>> Hi Kenneth,
>>
>> that's a DBIC question
>>
>>
>> anyways, what is the output of ...
>>
>> if ( $dept ) {
>>    warn "REF: " . ref $dept . " DEPT_ID: " . $dept->department_id;
>> } else {
>>    warn "No dept found";
>> }
>>
>> ... after your query?
>>
>> On 13 June 2012 22:54, Kenneth S Mclane <ksmclane [at] us> wrote:
>> > I am trying to get the value from a model call into a variable so I can
>> > use
>> > it for creating a DB record. I have tried multiple ways and cannot get
>> > the
>> > value to return. Here is my current attempt:
>> >
>> > my $dept =
>> > $c->model('ORANGES::Departments')->search_rs({'department_code'
>> > => $departmentcode}, {
>> >                 columns => ['department_id'] });
>> >
>> > This returns "1".
>> >
>> > I tried this:
>> >
>> > my $dept =
>> > $c->model('ORANGES::Departments')->search_rs({'department_code'
>> > => $departmentcode}, {
>> >                 columns => ['department_id'] })->single;
>> >
>> > and got a hash reference. I know I am missing something very simple. If
>> > I
>> > was putting this into the stash I know I could access the value, but I
>> > am at
>> > a loss as to how to get to it inside my code.
>> >
>> >
> [error] Caught exception in dbms::Controller::Account->add "Can't locate
> object method "department_id" via package "DBIx::Class::ResultSet" at
> /home/ksmclane/catalyst/dbms/script/../lib/dbms/Controller/Account.pm line
> 49."
>
>
> _______________________________________________
> List: Catalyst [at] lists
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
> Dev site: http://dev.catalyst.perl.org/
>

your $dept is a resultset not a row item
use the following code to get $dept

my $dept =
$c->model('ORANGES::Departments')->search_rs(
{ 'department_code' => $departmentcode},
{ columns => ['department_id'] }
)->single;

warn ...; # what I wrote earlier

assuming the rest of your code is corrent this should return a row
object with a department_id accessor ($dept->department_id)

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/

Catalyst users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.