[jifty-devel] Modeling Hierarchies
Rob Duncan
duncan at rejiquar.com
Mon Dec 11 12:32:51 EST 2006
I've been trying to reimplement an existing web app using Jifty. I really
like what I've seen with this framework so far. What I haven't seen is a
way to express a hierarchical relationship using the orm schema. Any
pointers, including "we answered that question on the list in July" would
be most appreciated.
For example, suppose I have a Model Tree:
package MyApp::Model::Tree;
use Jifty::DBI::Schema;
use MyApp::Record schema {
column name =>
type is 'text',
length is 60,
is mandatory;
column parent =>
type is 'INTEGER',
refers_to MyApp::Model::Tree,
render_as 'Text';
};
I can easily get to a (parent) node by its id. I can also display its
children by
my $subtree = MyApp::Model::TreeCollection->new();
$subtree->limit(column => 'parent', operator => '=', value => $parent_id);
Two questions:
1) What would be the best way to add a 'parent' method to the model?
Right now I am doing the ugly:
{
my $pt = MyApp::Model::TreeCollection->new();
$pt->limit(column => 'id', operator => '=', value => parent_id);
$parent = $pt->first();
}
in a template, where I don't think it belongs.
2) What's the best way to display a master/detail record set on a page?
(stuff about the parent, followed by the collection of children.)
More information about the jifty-devel
mailing list