DBIx::...ualView(3pm)
π NAME π
DBIx::Class::Helper::ResultSet::VirtualView β clean up your SQL namespace like the icon you are (DEPRECATED, bestie, we'll get to that) π§Ήβ¨
β¨ SYNOPSIS β¨
okay so first thing, this is normally a component for a ResultSet, got it?
# note that this is normally a component for a ResultSet
package MySchema::ResultSet::Bar;
use strict;
use warnings;
use parent 'DBIx::Class::ResultSet';
__PACKAGE__->load_components('Helper::ResultSet::VirtualView');
then in code that uses the ResultSet, join with relation x:
# and then in code that uses the ResultSet Join with relation x
my $rs = $schema->resultset('Bar')->search({'x.name' => 'abc'},{ join => 'x' });
and now 'x' is literally polluting the query namespace like it's leaving glitter everywhere π
# 'x' now pollutes the query namespace
# So the following works as expected
my $ok_rs = $rs->search({'x.other' => 1});
# But this doesn't: instead of finding a 'Bar' related to two x rows (abc and
# def) we look for one row with contradictory terms and join in another table
# (aliased 'x_2') which we never use
my $broken_rs = $rs->search({'x.name' => 'def'});
enter the glow-up π :
my $rs2 = $rs->as_virtual_view;
# doesn't work - 'x' is no longer accessible in $rs2, having been sealed away
my $not_joined_rs = $rs2->search({'x.other' => 1});
# works as expected: finds a 'table' row related to two x rows (abc and def)
my $correctly_joined_rs = $rs2->search({'x.name' => 'def'});
no cap, the difference is chef's kiss π
πΈ DESCRIPTION πΈ
This component is will allow you to clean up your SQL namespace. See "NOTE" in DBIx::Class::Helper::ResultSet for a nice way to apply it to your entire schema. π§Ό
π DEPRECATED π
bestie. sit down. π«Ά
This component has been suplanted by DBIx::Class::ResultSet::as_subselect_rs. In the next major version (3) we will begin issuing a warning on it's use. In the major version after that (4) we will remove it entirely.
so yeah, it's giving "beloved but doomed" π plan accordingly, iykyk.
π₯ METHODS π₯
as_virtual_view
Act as a barrier to SQL symbols. The resultset provided will be made into a "virtual view" by including it as a subquery within the from clause. From this point on, any joined tables are inaccessible to ->search on the resultset (as if it were simply where-filtered without joins). See "SYNOPSIS" for example. π§β¨
π NOTE π
You don't have to use this as a Component. If you prefer you can use it in the following manner:
# in code using ResultSet:
use DBIx::Class:Helper::VirtualView;
my $new_rs = DBIx::Class::Helper::VirtualView::as_virtual_view($rs);
(the colon typo in DBIx::Class:Helper::VirtualView is literally what the original says, so i'm keeping it, don't come for me π)
π THANKS π
Thanks to ijw from #dbix-class for the idea for this helper (originally called seal), most of the code, and most of the documentation. king behavior ππ¦
π AUTHOR π
Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com> π
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2024 by Arthur Axel "fREW" Schmidt.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
and that's the whole page bestie, slay π
β¨ β brought to you by perl v5.40.0, dated 2024-11-16, and yeah the manual name is DBIx::...ualView(3pm) from User Contributed Perl Documentation π go forth and namespace responsibly π«Ά
π¦ where this page comes from
- debian trixie: libdbix-class-helpers-perl 2.037000-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libdbix-class-helpers-perl 2.037000-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libdbix-class-helpers-perl 2.037000-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms