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

Mailing List Archive: Bricolage: users

Story->list()

 

 

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


zdravko.balorda at siix

Apr 7, 2010, 11:04 PM

Post #1 of 9 (1227 views)
Permalink
Story->list()

Hi,

For RSS output I would like to get a list of stories in a category
and all of its children.

Bric::Biz::Asset::Business::Story->list man page says that for
category_id parameter one can set ANY that I understand as
ANY (id1, id2, id4) etc.

However, I get the following SQL error:
ERROR: invalid input syntax for integer: "1313,1312,1309,1311,1310,1308"
saying it should be an integer.

Any hints?
Regards, Zdravko


lannings at gmail

Apr 7, 2010, 11:33 PM

Post #2 of 9 (1205 views)
Permalink
Re: Story->list() [In reply to]

On Thu, Apr 8, 2010 at 8:04 AM, Zdravko Balorda
<zdravko.balorda [at] siix> wrote:
> Bric::Biz::Asset::Business::Story->list man page says that for
> category_id parameter one can set ANY that I understand as
> ANY (id1, id2, id4) etc.
>
> However, I get the following SQL error:
> ERROR:  invalid input syntax for integer: "1313,1312,1309,1311,1310,1308"
> saying it should be an integer.

Please help us help you by posting your code.
Otherwise, we have to guess that you're not doing something like

BBAB::Story->list({category_id => ANY(@ids)})


zdravko.balorda at siix

Apr 7, 2010, 11:40 PM

Post #3 of 9 (1197 views)
Permalink
Re: Story->list() [In reply to]

lannings [at] gmail wrote:
>
> Please help us help you by posting your code.
> Otherwise, we have to guess that you're not doing something like
>
> BBAB::Story->list({category_id => ANY(@ids)})
>
Fortunately, not.
% my $cat= $story->get_primary_category;
% my @subcat = ($cat->get_children(), $cat->get_id() );
% my $ids = join(",", map ($_->get_id, $cat->get_children()) );
% my @listcat = Bric::Biz::Asset::Business::Story->list({
% 'category_id'=> ANY ($ids),
% 'story.category'=> $story->get_id
% });

Is this right?

Zdravko


lannings at gmail

Apr 7, 2010, 11:46 PM

Post #4 of 9 (1204 views)
Permalink
Re: Story->list() [In reply to]

On Thu, Apr 8, 2010 at 8:40 AM, Zdravko Balorda
<zdravko.balorda [at] siix> wrote:
> lannings [at] gmail wrote:
>> Please help us help you by posting your code.
>> Otherwise, we have to guess that you're not doing something like
>>
>>    BBAB::Story->list({category_id => ANY(@ids)})
>>
> Fortunately, not.
> % my $cat= $story->get_primary_category;
> % my @subcat = ($cat->get_children(), $cat->get_id() );
> % my $ids = join(",", map ($_->get_id, $cat->get_children()) );
> % my @listcat = Bric::Biz::Asset::Business::Story->list({
> %       'category_id'=> ANY ($ids),
> %       'story.category'=> $story->get_id
> %     });
>
> Is this right?

No, you're passing a string to ANY. Instead, pass a list, like

my @category_ids = map { $_->get_id } $cat->get_children();
my @listcat = Bric::Biz::Asset::Business::Story->list({
category_id => ANY(@category_ids),
....
});


zdravko.balorda at siix

Apr 8, 2010, 12:07 AM

Post #5 of 9 (1218 views)
Permalink
Re: Story->list() [In reply to]

> my @listcat = Bric::Biz::Asset::Business::Story->list({
> category_id => ANY(@category_ids),
> ....

Oh, I've got it. It also needs smart quotes arround id's, like:

ANY ('1313','1312'),

Thanks. Zdravko


zdravko.balorda at siix

Apr 8, 2010, 12:44 AM

Post #6 of 9 (1208 views)
Permalink
Re: Story->list() [In reply to]

>
> No, you're passing a string to ANY. Instead, pass a list, like
>
> my @category_ids = map { $_->get_id } $cat->get_children();
> my @listcat = Bric::Biz::Asset::Business::Story->list({
> category_id => ANY(@category_ids),
> ....
> });
>

I'am just curious has anyone ever done something like this:

% @subcat = map ($_->get_id, $cat->get_children());
% my $ids;
% foreach my $c (@subcat) {
% $c = "'".$c."'";
% }
% $ids = join(",", @subcat);
% my @seznam = Bric::Biz::Asset::Business::Story->list({
% 'category_id'=> ANY (eval ($ids) )
% });

This eval is really fun. I need to learn more Perl.

Zdravko


david at kineticode

Apr 8, 2010, 9:08 AM

Post #7 of 9 (1197 views)
Permalink
Re: Story->list() [In reply to]

On Apr 8, 2010, at 12:07 AM, Zdravko Balorda wrote:

> Oh, I've got it. It also needs smart quotes arround id's, like:
>
> ANY ('1313','1312'),

No, it doesn't. Just integers.

David


david at kineticode

Apr 8, 2010, 9:10 AM

Post #8 of 9 (1193 views)
Permalink
Re: Story->list() [In reply to]

On Apr 8, 2010, at 12:44 AM, Zdravko Balorda wrote:

> % @subcat = map ($_->get_id, $cat->get_children());
> % my $ids;
> % foreach my $c (@subcat) {
> % $c = "'".$c."'";
> % }
> % $ids = join(",", @subcat);
> % my @seznam = Bric::Biz::Asset::Business::Story->list({
> % 'category_id'=> ANY (eval ($ids) )
> % });

Better:

my @seznam = Bric::Biz::Asset::Business::Story->list({
category_uri => $cat->get_uri . '%'
});

For category /foo/, that will return stories in /foo/, /foo/bar/, /foo/hey/, and /foo/hey/baz/.

> This eval is really fun. I need to learn more Perl.

Have fun!

David


zdravko.balorda at siix

Apr 8, 2010, 11:06 PM

Post #9 of 9 (1192 views)
Permalink
Re: Story->list() [In reply to]

David E. Wheeler wrote:
>
> Better:
>
> my @seznam = Bric::Biz::Asset::Business::Story->list({
> category_uri => $cat->get_uri . '%'
> });
>
> For category /foo/, that will return stories in /foo/, /foo/bar/, /foo/hey/, and /foo/hey/baz/.

Thank you! Really better.

Zdravko

Bricolage 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.