OK, I got it working, there was issue with quote.
Now I can get all the sub categories belongs to one category by following
$schema->resultset('Cat')->search({name => 'Cat1'})->next->descendants;
I have following relationship.
Cat.pm
__PACKAGE__->has_many("cat_user", "MegaKBM::Schema::Result::UserCat",{
"foreign.user_id" => "self.id"},);
__PACKAGE__->many_to_many("c_users", "cat_user", "usercat");
UserCat.pm
__PACKAGE__->belongs_to("usercat","MegaKBM::Schema::Result::User",{ id =>
"user_id"},{ join_type => "LEFT"} );
__PACKAGE__->belongs_to("cat","MegaKBM::Schema::Result::Cat",{ id =>
"user_id"},{ join_type => "LEFT"} );
User.pm
__PACKAGE__->has_many("user_cat", "MegaKBM::Schema::Result::UserCat",{
"foreign.user_id" => "self.id" });
__PACKAGE__->many_to_many(u_cat => "user_cat" => "cat");
How can I get all users belongs to one category.
If I use my $rs = $schema->resultset('Cat')->search({name => 'Cat1'})->next;
$rs->c_users;
it works and give all users belongs to category Cat1.
If I use my $rs = $schema->resultset('Cat')->search({name =>
'Cat1'})->next->descendants;
$rs->c_users does not work because it has many sub categories.
Is it possible ? how?
Thanks
On Sat, Dec 18, 2010 at 7:57 PM, linuxsupport <[email protected]> wrote:
> I have created the table as show in the example
> fields are id, parent_id, lft, rgt, level and name.
>
> Now I am adding the data as following.
>
> my $root = $schema->resultset('Cat')->create({name => 'Cat'});
> $root->add_to_children({ name => 'cat1'});
>
> if I call $root->children i get following error.
>
> Schema::Result::Cat::children(): DBI Exception: DBD::mysql::st execute
> failed: Table 'sysitm.cat me, cat parent' doesn't exist [for Statement
> "SELECT `me`.`id`, `me`.`parent_id`, `me`.`lft`, `me`.`rgt`, `me`.`level`,
> `me`.`name` FROM `cat me, cat parent` WHERE ( ( `parent`.`id` = ? AND (
> `me`.`parent_id` = ? AND me.lft > parent.lft AND me.rgt < parent.rgt AND
> me.level = parent.level + 1 ) ) ) ORDER BY `me`.`lft`" with ParamValues:
> 0='3', 1='0'] at ./mytest.pl line 31
>
> Basically, what I want is categories and their sub categories there can be
> multi level sub categories, see below.
>
> Cat1 -> subcat1->subcat2
> ------> subcat3 -> subcat4 -> subcat5
> Cat2 -> subcat1 -> subcat2 ->subcat3
> -------> subcat5 -> subcat6
> -------> subcat7
>
> Thanks
>
> On Sat, Dec 18, 2010 at 4:31 PM, David Schmidt <[email protected]> wrote:
>
>> On Sat, Dec 18, 2010 at 7:20 AM, linuxsupport <[email protected]>
>> wrote:
>> > Hi,
>> >
>> > Can someone provide me a real example of Tree::NestedSet?
>> >
>> > Thanks
>> >
>> > _______________________________________________
>> > List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
>> > IRC: irc.perl.org#dbix-class
>> > SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
>> > Searchable Archive:
>> > http://www.grokbase.com/group/[email protected]
>> >
>>
>> Have you tried the example in the documentation? If yes and it failed
>> for you perhaps providing the error message would help.
>>
>> david
>>
>> _______________________________________________
>> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
>> IRC: irc.perl.org#dbix-class
>> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
>> Searchable Archive:
>> http://www.grokbase.com/group/[email protected]
>>
>
>
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]