Aaron Trevena wrote:
> On Thu, 18 Nov 2004, Brian Glass wrote:
>
>> Aaron Trevena wrote:
>>
>>> On Thu, 30 Sep 2004, Matt Adams wrote:
>>>
>>>> Brian Glass wrote:
>>>>
>>>>> Regardless, I do agree with Simon that something needs to change
>>>>> in the
>>>>> way Class::DBI::AsForm works in Maypole. It would make thinks
>>>>> considerably snappier.
>>>>
>>>>
>>>>
>>>> A solution that I implemented yesterday involved addressing
>>>> CDBI::AsForm's desire to create a drop-down every time it
>>>> encounters a has_a relationship.
>>>> To evade CDBI::AsForm's annoying habits I created a new View class,
>>>> overloaded the vars() method supplied by Maypole::View::Base and
>>>> changed
>>>
>>>
>>>
>>> I've come accross the unnecessary use of collections of objects a
>>> few times like this. There is no reason to fetch a bunch of objects,
>>> initialise and instantiate them all for a dropdown or select.
>>>
>>> I would really like to get hasMany relationships pulled as simple 2d
>>> arrays of id and name. I used this before when using tangram and
>>> drastically reduced the time it took to fetch long lists for
>>> dropdowns and lists.
>>>
>>> Some kind of
>>> $object->ForeignObjectName_asIndex($optional_id_column,$optional_title_column);
>>> would be very useful in CDBI for these kinds of relationships.
>>
>
>> Did you ever come up with a solution for this? If so I'd like to see it.
>
>
> I have implemented it in Class::DBI::Relationship::HasManyOrdered, it
> should be trivial to copy to your own class.
>
> I would like to see Maypole handle something like this for the many
> occasions when you only use the name and id of a load of objects and
> don't need the objects themselves.
>
> If anybody gives me some pointers I would be happy to amend and
> release a template and an updated view class or something (should be
> under an hours work).
>
> regards,
>
> A.
>
I did this using custom SQL. I 'use' the following package in my
controller class and then I've written a Mason template that looks at
the meta() info for the class/object and does the appropriate thing for
any field. It calls simple_list (from the module below) for fields with
relationships. I can post the template if people are interested. I would
imagine that it could be converted to TT pretty easily.
I only use AsForm for non-relationship fields. It turned out that the
real performance problems were created by object creation, not large
queries or MySQL. This little tweak makes my Maypole application very fast.
package SimpleList;
use strict;
use warnings;
sub import
{
my $caller = caller();
no strict 'refs';
*{"$caller\::simple_list"} = sub {
my $class = shift;
my %args = @_;
my $dbh = $class->db_Main;
my $table = $class->table;
my $primary = $class->primary_column;
my $column;
if( exists $args{column} ){
$column = $args{column};
}else{
$column = $class->stringify_column;
($column) = grep( /_name$/, $class->columns ) unless $column;
}
if( exists $args{order_by} ){
$dbh->selectall_arrayref( qq{
SELECT $primary, $column
FROM $table
ORDER BY $args{order}
});
}else{
$dbh->selectall_arrayref( qq{
SELECT $primary, $column
FROM $table
});
}
};
}
1;
_______________________________________________
maypole mailing list
maypole at lists.netthink.co.uk
http://lists.netthink.co.uk/listinfo/maypole
This archive was generated by hypermail 2.1.3 : Thu Feb 24 2005 - 22:25:57 GMT