Alzabo
view release on metacpan or search on metacpan
lib/Alzabo/Runtime/Schema.pm view on Meta::CPAN
=for pod_merge driver
=for pod_merge rules
=for pod_merge sqlmaker
=head1 JOINING A TABLE MORE THAN ONCE
It is possible to join to the same table more than once in a query.
Table objects contain an L<C<alias()>|Alzabo::Runtime::Table/alias>
method that, when called, returns an object that can be used in the
same query as the original table object, but which will be treated as
a separate table. This faciliaties queries similar to the following
SQL::
SELECT ... FROM Foo AS F1, Foo as F2, Bar AS B ...
The object returned from the table functions more or less exactly like
a table object. When using this table to set where clause or order by
(or any other) conditions, it is important that the column objects for
these conditions be retrieved from the alias object.
For example:
my $foo_alias = $foo->alias;
my $cursor = $schema->join( select => $foo,
join => [ $foo, $bar, $foo_alias ],
where => [ [ $bar->column('baz'), '=', 10 ],
[ $foo_alias->column('quux'), '=', 100 ] ],
order_by => $foo_alias->column('briz') );
If we were to use the C<$foo> object to retrieve the 'quux' and
'briz' columns then the join would simply not work as expected.
It is also possible to use multiple aliases of the same table in a
join, so that this will work properly:
my $foo_alias1 = $foo->alias;
my $foo_alias2 = $foo->alias;
=head1 USER AND PASSWORD INFORMATION
This information is never saved to disk. This means that if you're
operating in an environment where the schema object is reloaded from
disk every time it is used, such as a CGI program spanning multiple
requests, then you will have to make a new connection every time. In
a persistent environment, this is not a problem. For example, in a
mod_perl environment, you could load the schema and call the
L<C<set_user()>|Alzabo::Runtime::Schema/set_user ($user)> and
L<C<set_password()>|Alzabo::Runtime::Schema/set_password ($password)>
methods in the server startup file. Then all the mod_perl children
will inherit the schema with the user and password already set.
Otherwise you will have to provide it for each request.
You may ask why you have to go to all this trouble to deal with the
user and password information. The basic reason was that I did not
feel I could come up with a solution to this problem that was secure,
easy to configure and use, and cross-platform compatible. Rather, I
think it is best to let each user decide on a security practice with
which they feel comfortable.
In addition, there are a number of modules aimed at helping store and
use this sort of information on CPAN, including C<DBIx::Connect> and
C<AppConfig>, among others.
=head1 AUTHOR
Dave Rolsky, <autarch@urth.org>
=cut
( run in 0.714 second using v1.01-cache-2.11-cpan-ceb78f64989 )