Mailing List Archive

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
Re: Story->list() [ In reply to ]
On Thu, Apr 8, 2010 at 8:04 AM, Zdravko Balorda
<zdravko.balorda@siix.com> 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)})
Re: Story->list() [ In reply to ]
lannings@gmail.com 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
Re: Story->list() [ In reply to ]
On Thu, Apr 8, 2010 at 8:40 AM, Zdravko Balorda
<zdravko.balorda@siix.com> wrote:
> lannings@gmail.com 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),
....
});
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
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
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
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
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