[Maypole] has_a display name

Jesse Sheidlower jester@panix.com
Thu, 3 Jun 2004 13:34:12 -0400


On Thu, Jun 03, 2004 at 05:56:54PM +0100, Alex McLintock wrote:
> When I have a "has_a" relationship between two tables, using an id 
> field, how does "Maypole" figure out what field to use as the "pretty" 
> name for that field?
> Is it just any field with "name" in the name?

If there is such a field, Maypole will take that by default if
you don't specify anything else.

> Here is my example in case you are interested...
> 
> I have a relationship "title has_a author"
> SFBooksDB::Title->has_a(authornumber => "SFBooksDB::Author");
> 
> I can view and list titles of books, and the authornumber column comes 
> up with the authors "firstname" as a hyperlink instead of the integer 
> authornumber.
> This is great - and a step in the right direction. It does something 
> similar in the edit screen where there is a huge drop down list of *all* 
> the author firstnames.
> 
> But an author's firstname doesn't uniquely identify an author, and I 
> can't see where I said it did. I would actually like it to be the 
> concatenation of "firstname", "secondname", and "surname".

You want to take a look at the Class::DBI docs, under "Overloaded
Operators," and see what it says about stringification. For your
setup I expect you'll want something like

package SFBooksDB::Author;
#other stuff...

sub stringify_self { 
    my $self = shift;
    return join " ", $self->firstname, $self->secondname, $self->surname;
}

1;


HTH.

Jesse Sheidlower