Suppose you have a main table Album with relation artist to table Artist where you have added a virtual column album_count.
package Album;
...
...
__PACKAGE__->belongs_to( artist => 'MySchema::Result::Artist', { id => 'artist_id' };
virtual_columns => {
Artist => {
album_count => {
sql => q/ SELECT COUNT(*) FROM album WHERE album.artist_id = self.id /
}
}
}
Now suppose you select columns for an Album grid, and choose artist.album_count without selecting any other fields from artist. DBIC strips out the join to the artist table because no concrete columns were using it, and then the SQL fails because it generated
SELECT ..., (SELECT COUNT(*) FROM album WHERE album.artist_id = artist.id )
FROM album me
WHERE ...
and artist is not defined.
This could be fixed by the code checking for the case where a virtual column is the only column using a join, and then just add some un-needed column (like the primary key) so DBIC doesn't strip it out.
Suppose you have a main table
Album
with relationartist
to tableArtist
where you have added a virtual columnalbum_count
.Now suppose you select columns for an Album grid, and choose
artist.album_count
without selecting any other fields from artist. DBIC strips out the join to theartist
table because no concrete columns were using it, and then the SQL fails because it generatedand
artist
is not defined.This could be fixed by the code checking for the case where a virtual column is the only column using a join, and then just add some un-needed column (like the primary key) so DBIC doesn't strip it out.
Or, maybe just unconditionally add the primary columns of the related table any time a virtual column is used?