Hello all,
I have question about using DBIx::Tree::NestedSet and using it. My aim is very easy, I have some categories and I'd like to store them in DB as tree. I found this nice module, I like it, but I run into problems and I don't know what to do further.
here is snippet what I wrote:
use strict;
use warnings;
use DBIx::Tree::NestedSet;
use DBI;
my $dbh = DBI->connect('DBI:mysql:test','root','')
or die ($DBI::errstr);
my $tree = DBIx::Tree::NestedSet->new( dbh => $dbh,
no_locking => 1,
table_name => 'db_tree'
);
$dbh->do("DELETE from db_tree");
#we can't have more "top" categories, so we create "main"
$tree->add_child_to_right( name=>'main' );
while (<DATA>) {
chomp;
my $hr;
for my $item ( split '/' ) {
$hr->{last_id} = $tree->add_child_to_right(
name => $item,
id => $hr->{last_id}
);
}
}
print "\nThe Complete Tree:\n";
print $tree->create_report();
__DATA__
foo/bar
bar/foo
foo/bar/foo
Output is:
The Complete Tree:
main (354)(1)
foo (355)(2)
bar (356)(3)
bar (357)(2)
foo (358)(3)
foo (359)(2)
bar (360)(3)
foo (361)(4)
Ok, now problem - I don't want to have "foo/bar" and "foo/bar/foo" as separate paths, but instead only one: "foo/bar/foo"
could anyone help me please ?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.