Re: [Catalyst] Retrieve all users belong to a category and all its sub categories

2010-12-17 Thread will trillich
/lurk

Ooh, I didn't know about either of those. Very, very sweet! And one for
nested-sets and another for parent-links/adjacency lists.

This is what's so great about open source mailing lists -- the serendipity.
Here on a Catalyst web-framework list you learn cool, tangential things
about DBIC that you didn't know you were missing, and then you can just go
nab new tools that make life easy!

Awesome.


On Thu, Dec 16, 2010 at 11:36 PM, Charlie Garrison garri...@zeta.org.auwrote:

 Good morning,


 On 16/12/10 at 11:15 AM -0500, Hauck, William B. william.ha...@ibx.com
 wrote:

  Not sure how to do it in a DBIC-like fashion, but these few links show you
 how to do it in SQL for PostgreSQL and MySQL.  Oracle and DB2 have
 hierarchical functionality built-in.

 http://www.postgresql.org/docs/8.4/static/queries-with.html

 http://dev.mysql.com/tech-resources/articles/hierarchical-data.html

 http://onlamp.com/lpt/a/5007


 I haven't been following this thread closely, but I think one of the
 DBIC::Tree modules is what OP is looking for:

 http://search.cpan.org/perldoc?DBIx::Class::Tree::AdjacencyList
 http://search.cpan.org/perldoc?DBIx::Class::Tree::NestedSet


 Charlie

 --
   Ꮚ Charlie Garrison ♊ garri...@zeta.org.au

 O ascii ribbon campaign - stop html mail - www.asciiribbon.org
 〠  http://www.ietf.org/rfc/rfc1855.txt


 ___
 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/




-- 
Failure is not important. How you overcome it, is.
-- Nick Vujicic
___
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/


Re: [Catalyst] Retrieve all users belong to a category and all its sub categories

2010-12-17 Thread linuxsupport
OK, I switched to Tree::NestedSet.

Can someone give me real example, its not working for me.

Thanks

On Fri, Dec 17, 2010 at 8:22 PM, will trillich
will.trill...@serensoft.comwrote:

 /lurk

 Ooh, I didn't know about either of those. Very, very sweet! And one for
 nested-sets and another for parent-links/adjacency lists.

 This is what's so great about open source mailing lists -- the serendipity.
 Here on a Catalyst web-framework list you learn cool, tangential things
 about DBIC that you didn't know you were missing, and then you can just go
 nab new tools that make life easy!

 Awesome.


 On Thu, Dec 16, 2010 at 11:36 PM, Charlie Garrison 
 garri...@zeta.org.auwrote:

 Good morning,


 On 16/12/10 at 11:15 AM -0500, Hauck, William B. william.ha...@ibx.com
 wrote:

  Not sure how to do it in a DBIC-like fashion, but these few links show
 you how to do it in SQL for PostgreSQL and MySQL.  Oracle and DB2 have
 hierarchical functionality built-in.

 http://www.postgresql.org/docs/8.4/static/queries-with.html

 http://dev.mysql.com/tech-resources/articles/hierarchical-data.html

 http://onlamp.com/lpt/a/5007


 I haven't been following this thread closely, but I think one of the
 DBIC::Tree modules is what OP is looking for:

 http://search.cpan.org/perldoc?DBIx::Class::Tree::AdjacencyList
 http://search.cpan.org/perldoc?DBIx::Class::Tree::NestedSet


 Charlie

 --
   Ꮚ Charlie Garrison ♊ garri...@zeta.org.au

 O ascii ribbon campaign - stop html mail - www.asciiribbon.org
 〠  http://www.ietf.org/rfc/rfc1855.txt


 ___
 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/




 --
 Failure is not important. How you overcome it, is.
 -- Nick Vujicic

 ___
 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/


___
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/


Re: [Catalyst] Retrieve all users belong to a category and all its sub categories

2010-12-16 Thread linuxsupport
Thanks, it worked.

But how to do it If I have sub categories of sub category?

Example is below.

id  name   parent _id
1   cat10
2   cat21
3   cat3 0
4   cat4 2
5   cat5 4

Here, I have cat1  cat2 - cat4  cat5, there may be sub categories of any
of sub category.

Thanks

On Fri, Dec 10, 2010 at 9:12 AM, Emmanuel Otton ot...@mines-albi.fr wrote:

  Le 09/12/2010 09:37, linuxsupport a écrit :

 I have 3 tables, users, user_cat, and cat, table structure and relationship
 are setup as follows.
 User.pm
 __PACKAGE__-add_columns(
   id, { data_type = integer, is_nullable = 0 },
   username,{ data_type = text, is_nullable = 1 },
   password,  { data_type = text, is_nullable = 1 },
   email_address,  { data_type = text, is_nullable = 1 },
   first_name,  { data_type = text, is_nullable = 1 },
   last_name,  { data_type = text, is_nullable = 1 },
   active,  { data_type = integer, is_nullable = 1 },
 );
 __PACKAGE__-set_primary_key(id);
 __PACKAGE__-has_many(usercats, Example::Schema::Result::UserCat,{
 foreign.user_id = self.id },);
 __PACKAGE__-many_to_many(cats = 'usercats', 'cat');

 UserCat.pm
 __PACKAGE__-add_columns(
   user_id,  { data_type = integer, is_nullable = 0 },
   cat_id,  { data_type = integer, default_value = 0, is_nullable = 0
 },
 );
 __PACKAGE__-set_primary_key(user_id, cat_id);
 __PACKAGE__-belongs_to(user, Example::Schema::Result::User, { id =
 user_id },{ join_type = LEFT },);
 __PACKAGE__-belongs_to(cat, Example::Schema::Result::Cat, { id =
 cat_id },{ join_type = LEFT },);

 Cat.pm
 __PACKAGE__-add_columns(
   id,  { data_type = integer, is_nullable = 0 },
   cat_name,  { data_type = text, is_nullable = 0 },
  parent_id,  { data_type = integer, is_nullable = 0 },
 );
 __PACKAGE__-set_primary_key(id,parent_id);
 __PACKAGE__-has_many(usercat,Example::Schema::Result::UserCat,{
 foreign.cat_id = self.id },);
 __PACKAGE__many_to_many(allcat, usercat', cat);

 I am able to retrieve all users in any particular category using allcat
 many_to_many relationship.

 Are you, really ?
 The navigation path you indicate in your allcat many_to_many relationship
 does not seem to lead from Cat to Users but from Cat to Cat itself, which
 seems of no practical use.

 I rather would have written:
 __PACKAGE__-many_to_many(users,usercat,user);

 So that I can get the users in any category this way:
 my $cat = $schema-resultset(Cat)-find($my_cat_id);
 my @users_belonging_directly_to_that_category = $cat-users;


  In cat table I have both category and sub category, if a row have
 parent_id  0 then it is sub category.
 How can I get all users belong to one category and its sub categories?

 Now to get recursively all users belonging to this category AND all
 sub-categories is another problem.

 The procedural/Perlish/DBIx::Classish solution would be:
 # first, add to Cat.pm an accessor to the sub-categories
 __PACKAGE__-has_many(subcats,Example::Schema::Result::Cat,{
 foreign.parent_id = self.id });

 # then, in your program:
 my $cat = $schema-resultset(Cat)-find($my_cat_id);
 my @users_belonging_to_that_category_and_its_subcats = $cat-users;

 my @subcats = $cat-subcats;
 for my $subcat (@subcats)
 push @users_belonging_to_that_category_and_its_subcats , $cat-users;
 }
 # assuming the reflexive relationship is one level only
 # i.e. no sub-sub-..etc..-categories


 A (better in my -humble- opinion) solution would be more SQL-oriented
 (after all, isn't the declarative SQL way the reason why we all use RDBMSes
 ?)

 First of all, create a view giving what you want:

 create view users_by_cat_and_subcats as
 select cat.id cat_id, user.*
   from cat join usercat on usercat.cat_id = cat.id
   join user on user.id = usercat.user_id
 union select parent.cat.id cat_id , user.*
   from cat parent_cat join cat child_cat on child_cat.parent_id =
 parent_cat.cat_id
   join usercat on usercat.cat_id = child_cat.id
   join user on user.id = usercat.user_id ;

 Then create (automatically, by make_schema_at) a UsersByCatAndSubcat.pm to
 map this table to a DBIx::Class and just use it:
 my @users_belonging_to_that_category_and_its_subcats =
$schema-resultset('UsersByCatAndSubcat')-search( { cat_id =
 $my_category } )-all;

 It's always difficult to use the right tool, and I've seen ugly things like
 simple left joins replaced by 15 lines of while, if defined, push,etc...
 RDBMSes have dominated our domain for nearly forty years for a reason,
 which is the expressive power of SQL, itself based on strong theoretical
 mathematical background.
 My advice is: don't forget you have a RDBMS, and thus the full power of
 SQL, at your disposal.

 Sorry for this answer to a slightly off-catalyst-topic question; I will
 subscribe to the DBIx::Class list right away.

 --
 Emmanuel Otton - Ecole des mines d'Albi-Carmaux - département informatique - 
 Tél: 05 63 49 30 86


 ___
 List: 

Re: [Catalyst] Retrieve all users belong to a category and all its sub categories

2010-12-16 Thread Hauck, William B.
Not sure how to do it in a DBIC-like fashion, but these few links show you how 
to do it in SQL for PostgreSQL and MySQL.  Oracle and DB2 have hierarchical 
functionality built-in.

http://www.postgresql.org/docs/8.4/static/queries-with.html

http://dev.mysql.com/tech-resources/articles/hierarchical-data.html

http://onlamp.com/lpt/a/5007


On 12/16/10 4:40 AM, linuxsupport lin.supp...@gmail.com wrote:

Thanks, it worked.

But how to do it If I have sub categories of sub category?

Example is below.

id  name   parent _id
1   cat10
2   cat21
3   cat3 0
4   cat4 2
5   cat5 4

Here, I have cat1  cat2 - cat4  cat5, there may be sub categories of any of 
sub category.

Thanks

On Fri, Dec 10, 2010 at 9:12 AM, Emmanuel Otton ot...@mines-albi.fr wrote:

 Le 09/12/2010 09:37, linuxsupport a écrit :
I have 3 tables, users, user_cat, and cat, table structure and relationship are 
setup as follows.
 User.pm
 __PACKAGE__-add_columns(
   id, { data_type = integer, is_nullable = 0 },
   username,{ data_type = text, is_nullable = 1 },
   password,  { data_type = text, is_nullable = 1 },
   email_address,  { data_type = text, is_nullable = 1 },
   first_name,  { data_type = text, is_nullable = 1 },
   last_name,  { data_type = text, is_nullable = 1 },
   active,  { data_type = integer, is_nullable = 1 },
 );
 __PACKAGE__-set_primary_key(id);

__PACKAGE__-has_many(usercats, Example::Schema::Result::UserCat,{ 
foreign.user_id = self.id http://self.id/  },);
 __PACKAGE__-many_to_many(cats = 'usercats', 'cat');

 UserCat.pm
 __PACKAGE__-add_columns(
   user_id,  { data_type = integer, is_nullable = 0 },
   cat_id,  { data_type = integer, default_value = 0, is_nullable = 0 },
 );
 __PACKAGE__-set_primary_key(user_id, cat_id);
 __PACKAGE__-belongs_to(user, Example::Schema::Result::User, { id = 
user_id },{ join_type = LEFT },);
 __PACKAGE__-belongs_to(cat, Example::Schema::Result::Cat, { id = 
cat_id },{ join_type = LEFT },);

 Cat.pm
 __PACKAGE__-add_columns(
   id,  { data_type = integer, is_nullable = 0 },
   cat_name,  { data_type = text, is_nullable = 0 },
  parent_id,  { data_type = integer, is_nullable = 0 },
 );
 __PACKAGE__-set_primary_key(id,parent_id);
 __PACKAGE__-has_many(usercat,Example::Schema::Result::UserCat,{ 
foreign.cat_id = self.id http://self.id/  },);
 __PACKAGE__many_to_many(allcat, usercat', cat);

 I am able to retrieve all users in any particular category using allcat 
many_to_many relationship.


Are you, really ?
 The navigation path you indicate in your allcat many_to_many relationship 
does not seem to lead from Cat to Users but from Cat to Cat itself, which seems 
of no practical use.

 I rather would have written:
 __PACKAGE__-many_to_many(users,usercat,user);

 So that I can get the users in any category this way:
 my $cat = $schema-resultset(Cat)-find($my_cat_id);
 my @users_belonging_directly_to_that_category = $cat-users;




In cat table I have both category and sub category, if a row have parent_id  0 
then it is sub category.
 How can I get all users belong to one category and its sub categories?

Now to get recursively all users belonging to this category AND all 
sub-categories is another problem.

 The procedural/Perlish/DBIx::Classish solution would be:
 # first, add to Cat.pm an accessor to the sub-categories
 __PACKAGE__-has_many(subcats,Example::Schema::Result::Cat,{ 
foreign.parent_id = self.id http://self.id/  });

 # then, in your program:
 my $cat = $schema-resultset(Cat)-find($my_cat_id);
 my @users_belonging_to_that_category_and_its_subcats = $cat-users;

 my @subcats = $cat-subcats;
 for my $subcat (@subcats)
 push @users_belonging_to_that_category_and_its_subcats , $cat-users;
 }
 # assuming the reflexive relationship is one level only
 # i.e. no sub-sub-..etc..-categories


 A (better in my -humble- opinion) solution would be more SQL-oriented (after 
all, isn't the declarative SQL way the reason why we all use RDBMSes ?)

 First of all, create a view giving what you want:

 create view users_by_cat_and_subcats as
 select cat.id http://cat.id  cat_id, user.*
   from cat join usercat on usercat.cat_id = cat.id http://cat.id
   join user on user.id http://user.id  = usercat.user_id
 union select parent.cat.id http://parent.cat.id  cat_id , user.*
   from cat parent_cat join cat child_cat on child_cat.parent_id = 
parent_cat.cat_id
   join usercat on usercat.cat_id = child_cat.id http://child_cat.id
   join user on user.id http://user.id  = usercat.user_id ;

 Then create (automatically, by make_schema_at) a UsersByCatAndSubcat.pm to map 
this table to a DBIx::Class and just use it:
 my @users_belonging_to_that_category_and_its_subcats =
$schema-resultset('UsersByCatAndSubcat')-search( { cat_id = $my_category 
} )-all;

 It's always difficult to use the right tool, and I've seen ugly things like 
simple left joins replaced by 15 lines of while, if defined, push,etc...
 

Re: [Catalyst] Retrieve all users belong to a category and all its sub categories

2010-12-16 Thread Charlie Garrison

Good morning,

On 16/12/10 at 11:15 AM -0500, Hauck, William B. 
william.ha...@ibx.com wrote:


Not sure how to do it in a DBIC-like fashion, but these few 
links show you how to do it in SQL for PostgreSQL and MySQL.  
Oracle and DB2 have hierarchical functionality built-in.


http://www.postgresql.org/docs/8.4/static/queries-with.html

http://dev.mysql.com/tech-resources/articles/hierarchical-data.html

http://onlamp.com/lpt/a/5007


I haven't been following this thread closely, but I think one of 
the DBIC::Tree modules is what OP is looking for:


http://search.cpan.org/perldoc?DBIx::Class::Tree::AdjacencyList
http://search.cpan.org/perldoc?DBIx::Class::Tree::NestedSet


Charlie

--
   Ꮚ Charlie Garrison ♊ garri...@zeta.org.au

O ascii ribbon campaign - stop html mail - www.asciiribbon.org
〠  http://www.ietf.org/rfc/rfc1855.txt

___
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/


Re: [Catalyst] Retrieve all users belong to a category and all its sub categories

2010-12-10 Thread Emmanuel Otton

Le 09/12/2010 09:37, linuxsupport a écrit :
I have 3 tables, users, user_cat, and cat, table structure and 
relationship are setup as follows.

User.pm
__PACKAGE__-add_columns(
  id, { data_type = integer, is_nullable = 0 },
  username,{ data_type = text, is_nullable = 1 },
  password,  { data_type = text, is_nullable = 1 },
  email_address,  { data_type = text, is_nullable = 1 },
  first_name,  { data_type = text, is_nullable = 1 },
  last_name,  { data_type = text, is_nullable = 1 },
  active,  { data_type = integer, is_nullable = 1 },
);
__PACKAGE__-set_primary_key(id);
__PACKAGE__-has_many(usercats, Example::Schema::Result::UserCat,{ 
foreign.user_id = self.id http://self.id/ },);

__PACKAGE__-many_to_many(cats = 'usercats', 'cat');

UserCat.pm
__PACKAGE__-add_columns(
  user_id,  { data_type = integer, is_nullable = 0 },
  cat_id,  { data_type = integer, default_value = 0, is_nullable 
= 0 },

);
__PACKAGE__-set_primary_key(user_id, cat_id);
__PACKAGE__-belongs_to(user, Example::Schema::Result::User, { id 
= user_id },{ join_type = LEFT },);
__PACKAGE__-belongs_to(cat, Example::Schema::Result::Cat, { id = 
cat_id },{ join_type = LEFT },);


Cat.pm
__PACKAGE__-add_columns(
  id,  { data_type = integer, is_nullable = 0 },
  cat_name,  { data_type = text, is_nullable = 0 },
 parent_id,  { data_type = integer, is_nullable = 0 },
);
__PACKAGE__-set_primary_key(id,parent_id);
__PACKAGE__-has_many(usercat,Example::Schema::Result::UserCat,{ 
foreign.cat_id = self.id http://self.id/ },);

__PACKAGE__many_to_many(allcat, usercat', cat);

I am able to retrieve all users in any particular category using 
allcat many_to_many relationship.

Are you, really ?
The navigation path you indicate in your allcat many_to_many 
relationship does not seem to lead from Cat to Users but from Cat to Cat 
itself, which seems of no practical use.


I rather would have written:
__PACKAGE__-many_to_many(users,usercat,user);

So that I can get the users in any category this way:
my $cat = $schema-resultset(Cat)-find($my_cat_id);
my @users_belonging_directly_to_that_category = $cat-users;

In cat table I have both category and sub category, if a row have 
parent_id  0 then it is sub category.

How can I get all users belong to one category and its sub categories?
Now to get recursively all users belonging to this category AND all 
sub-categories is another problem.


The procedural/Perlish/DBIx::Classish solution would be:
# first, add to Cat.pm an accessor to the sub-categories
__PACKAGE__-has_many(subcats,Example::Schema::Result::Cat,{ 
foreign.parent_id = self.id http://self.id/ });


# then, in your program:
my $cat = $schema-resultset(Cat)-find($my_cat_id);
my @users_belonging_to_that_category_and_its_subcats = $cat-users;

my @subcats = $cat-subcats;
for my $subcat (@subcats)
push @users_belonging_to_that_category_and_its_subcats , $cat-users;
}
# assuming the reflexive relationship is one level only
# i.e. no sub-sub-..etc..-categories


A (better in my -humble- opinion) solution would be more SQL-oriented 
(after all, isn't the declarative SQL way the reason why we all use 
RDBMSes ?)


First of all, create a view giving what you want:

create view users_by_cat_and_subcats as
select cat.id cat_id, user.*
  from cat join usercat on usercat.cat_id = cat.id
  join user on user.id = usercat.user_id
union select parent.cat.id cat_id , user.*
  from cat parent_cat join cat child_cat on child_cat.parent_id = 
parent_cat.cat_id

  join usercat on usercat.cat_id = child_cat.id
  join user on user.id = usercat.user_id ;

Then create (automatically, by make_schema_at) a UsersByCatAndSubcat.pm 
to map this table to a DBIx::Class and just use it:

my @users_belonging_to_that_category_and_its_subcats =
   $schema-resultset('UsersByCatAndSubcat')-search( { cat_id = 
$my_category } )-all;


It's always difficult to use the right tool, and I've seen ugly things 
like simple left joins replaced by 15 lines of while, if defined, 
push,etc...
RDBMSes have dominated our domain for nearly forty years for a reason, 
which is the expressive power of SQL, itself based on strong theoretical 
mathematical background.
My advice is: don't forget you have a RDBMS, and thus the full power of 
SQL, at your disposal.


Sorry for this answer to a slightly off-catalyst-topic question; I will 
subscribe to the DBIx::Class list right away.


--
Emmanuel Otton - Ecole des mines d'Albi-Carmaux - département informatique - 
Tél: 05 63 49 30 86

___
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/


[Catalyst] Retrieve all users belong to a category and all its sub categories

2010-12-09 Thread linuxsupport
I have 3 tables, users, user_cat, and cat, table structure and relationship
are setup as follows.

User.pm

__PACKAGE__-add_columns(
  id,
  { data_type = integer, is_nullable = 0 },
  username,
  { data_type = text, is_nullable = 1 },
  password,
  { data_type = text, is_nullable = 1 },
  email_address,
  { data_type = text, is_nullable = 1 },
  first_name,
  { data_type = text, is_nullable = 1 },
  last_name,
  { data_type = text, is_nullable = 1 },
  active,
  { data_type = integer, is_nullable = 1 },
);
__PACKAGE__-set_primary_key(
id);

__PACKAGE__-has_many(usercats, Example::Schema::Result::UserCat,{
foreign.user_id = self.id },);
__PACKAGE__-many_to_many(cats = 'usercats', 'cat');

UserCat.pm

__PACKAGE__-add_columns(
  user_id,
  { data_type = integer, is_nullable = 0 },
  cat_id,
  { data_type = integer, default_value = 0, is_nullable = 0 },
);
__PACKAGE__-set_primary_key(user_id, cat_id);

__PACKAGE__-belongs_to(user, Example::Schema::Result::User, { id =
user_id },{ join_type = LEFT },);
__PACKAGE__-belongs_to(cat, Example::Schema::Result::Cat, { id =
cat_id },{ join_type = LEFT },);

Cat.pm

__PACKAGE__-add_columns(
  id,
  { data_type = integer, is_nullable = 0 },
  cat_name,
  { data_type = text, is_nullable = 0 },
 parent_id,
  { data_type = integer, is_nullable = 0 },
);
__PACKAGE__-set_primary_key(id,parent_id);

__PACKAGE__-has_many(usercat,Example::Schema::Result::UserCat,{
foreign.cat_id = self.id },);
__PACKAGE__many_to_many(allcat, usercat', cat);

I am able to retrieve all users in any particular category using allcat
many_to_many relationship.

In cat table I have both category and sub category, if a row have parent_id
 0 then it is sub category.

How can I get all users belong to one category and its sub categories?

Thanks in advance.
___
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/


Re: [Catalyst] Retrieve all users belong to a category and all its sub categories

2010-12-09 Thread David Schmidt
On Thu, Dec 9, 2010 at 9:37 AM, linuxsupport lin.supp...@gmail.com wrote:
 I have 3 tables, users, user_cat, and cat, table structure and relationship
 are setup as follows.

 User.pm

 __PACKAGE__-add_columns(
   id,
   { data_type = integer, is_nullable = 0 },
   username,
   { data_type = text, is_nullable = 1 },
   password,
   { data_type = text, is_nullable = 1 },
   email_address,
   { data_type = text, is_nullable = 1 },
   first_name,
   { data_type = text, is_nullable = 1 },
   last_name,
   { data_type = text, is_nullable = 1 },
   active,
   { data_type = integer, is_nullable = 1 },
 );
 __PACKAGE__-set_primary_key(
 id);

 __PACKAGE__-has_many(usercats, Example::Schema::Result::UserCat,{
 foreign.user_id = self.id },);
 __PACKAGE__-many_to_many(cats = 'usercats', 'cat');

 UserCat.pm

 __PACKAGE__-add_columns(
   user_id,
   { data_type = integer, is_nullable = 0 },
   cat_id,
   { data_type = integer, default_value = 0, is_nullable = 0 },
 );
 __PACKAGE__-set_primary_key(user_id, cat_id);

 __PACKAGE__-belongs_to(user, Example::Schema::Result::User, { id =
 user_id },{ join_type = LEFT },);
 __PACKAGE__-belongs_to(cat, Example::Schema::Result::Cat, { id =
 cat_id },{ join_type = LEFT },);

 Cat.pm

 __PACKAGE__-add_columns(
   id,
   { data_type = integer, is_nullable = 0 },
   cat_name,
   { data_type = text, is_nullable = 0 },
  parent_id,
   { data_type = integer, is_nullable = 0 },
 );
 __PACKAGE__-set_primary_key(id,parent_id);

 __PACKAGE__-has_many(usercat,Example::Schema::Result::UserCat,{
 foreign.cat_id = self.id },);
 __PACKAGE__many_to_many(allcat, usercat', cat);

 I am able to retrieve all users in any particular category using allcat
 many_to_many relationship.

 In cat table I have both category and sub category, if a row have parent_id
 0 then it is sub category.

 How can I get all users belong to one category and its sub categories?

 Thanks in advance.


 ___
 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/



That's entirely a DBIx::Class question. You might want to ask in
#dbix-class on irc.perl.org or at the DBIx::Class mailinglist
http://lists.scsys.co.uk/mailman/listinfo/dbix-class

david

___
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/