Re: Access to has_a data from Template?
[prev]
[thread]
[next]
[Date index for 2004/09/16]
On Thu, Sep 16, 2004 at 08:02:16PM +0100, Tony Bowden wrote:
> On Thu, Sep 16, 2004 at 01:39:47PM -0400, Jesse Sheidlower wrote:
> > On Thu, Sep 16, 2004 at 06:30:16PM +0100, Tony Bowden wrote:
> > > On Thu, Sep 16, 2004 at 07:28:52AM -0400, Jesse Sheidlower wrote:
> > > > Suppose I'm looking at a "book", each book being a
> > > > MyLibrary::Book, and each "book" has_a "format"
> > > > (hardcover, paperback, etc.). If I do:
> > > > [% USE book = Class("MyLibrary::Book") %]
> > > > I still can't seem to get to at the format data:
> > > > FOREACH format = book.format
> > > > bombs out with
> > > > undef error - Can't fetch data as class method at
> > >
> > > Well, of course it will. You're asking for the format of ALL books, which
> > > makes no sense. You presumably want the format of a particular book,
> > > which should be getting passed into the template somehow...
> > No, I want to access a "format" object, to call things on it.
>
> Which format object?
One that I will instantiate, if necessary, because it is related
to my book object.
> > The FOREACH was just an example, but in reality, I'd want to
> > retrieve_all from format, so I can construct a select list
> > (or whatever) from the results.
>
> Then why are you working with the Book class?
Because the main thing here is that I have a book object, with a
bunch of columns (some of which may belong to other classes
related to book).
> Instead of:
> > > > [% USE book = Class("MyLibrary::Book") %]
>
> You should be doing something like:
>
> [% USE bookformat = Class("MyLibrary::Book::Format") %]
> [% SET formats = bookformat.retrieve_all %]
>
> But really you'd be better off passing this sort of thing into the
> template in the first place.
I thought I was, via my book object.
Let me put it another way: given that I have a book object,
and that I know book has_a format, is there any way I can get
a format object? Without necessarily knowing that my format
class is MyLibrary::Book::Format? Can I get there from a
book object?
Thanks. Sorry to be dragging this out.
Jesse Sheidlower