[jifty-devel] Modeling Hierarchies
Rob Duncan
duncan at rejiquar.com
Tue Dec 12 10:30:03 EST 2006
An answer to part of my own question, in case it helps someone else:
On Mon, December 11, 2006 12:32 pm, Rob Duncan wrote:
> ... What I haven't seen is a
> way to express a hierarchical relationship using the orm schema. Any
> ...
> 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';
> };
> ...
> Two questions:
OK, I see the answer to part (1) has been staring me in the face: a
refers_to column returns an object, not the id. So $subtree->parent
already exists and does what I want.
> 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.
Still hoping for a pointer to master/detail display hints.
> 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