From: Alastair McGowan-Douglas Date: Fri, 7 Nov 2014 17:00:21 +0000 (+0000) Subject: Inflators are not respected by find() (being a ResultSet method) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b7fcdab3af6f5a8a0cbef74c0680b26828a8cf2f;p=dbsrgits%2FDBIx-Class.git Inflators are not respected by find() (being a ResultSet method) Adjust docs and add an extra IC::DT-specific FAQ section --- diff --git a/AUTHORS b/AUTHORS index 4088db9..aa0fe63 100644 --- a/AUTHORS +++ b/AUTHORS @@ -20,6 +20,7 @@ aherzog: Adam Herzog Alexander Keusch alexrj: Alessandro Ranellucci alnewkirk: Al Newkirk +Altreus: Alastair McGowan-Douglas amiri: Amiri Barksdale amoore: Andrew Moore Andrew Mehta diff --git a/Changes b/Changes index a9db781..3618e50 100644 --- a/Changes +++ b/Changes @@ -28,7 +28,7 @@ Revision history for DBIx::Class * Misc - Remove warning about potential side effects of RT#79576 (scheduled) - - Various doc improvements (GH#62, GH#70, GH#71, GH#72) + - Various doc improvements (GH#62, GH#66, GH#70, GH#71, GH#72) - Skip tests in a way more intelligent and speedy manner when optional dependencies are missing - Make the Optional::Dependencies error messages cpanm-friendly diff --git a/lib/DBIx/Class/Manual/Cookbook.pod b/lib/DBIx/Class/Manual/Cookbook.pod index cf80dd8..d08022a 100644 --- a/lib/DBIx/Class/Manual/Cookbook.pod +++ b/lib/DBIx/Class/Manual/Cookbook.pod @@ -1770,11 +1770,11 @@ C<< [column_name => value] >>. =head2 Formatting DateTime objects in queries To ensure C conditions containing L arguments are properly -formatted to be understood by your RDBMS, you must use the C +formatted to be understood by your RDBMS, you must use the L formatter returned by L to format any L objects you pass to L conditions. Any L object attached to your -L provides a correct C formatter, so +L provides a correct L formatter, so all you have to do is: my $dtf = $schema->storage->datetime_parser; @@ -1793,12 +1793,11 @@ Without doing this the query will contain the simple stringification of the C object, which almost never matches the RDBMS expectations. This kludge is necessary only for conditions passed to -L, whereas -L, -L, -L (but not L) are all +L and L, +whereas L and +L (but not L) are L-aware and will do the right thing when supplied -an inflated C object. +an inflated L object. =head2 Using Unicode diff --git a/lib/DBIx/Class/Manual/FAQ.pod b/lib/DBIx/Class/Manual/FAQ.pod index 92ac0f7..b8dbe17 100644 --- a/lib/DBIx/Class/Manual/FAQ.pod +++ b/lib/DBIx/Class/Manual/FAQ.pod @@ -262,6 +262,39 @@ alter session statements on database connection establishment: ->on_connect_do("ALTER SESSION SET NLS_SORT = 'BINARY_CI'"); ->on_connect_do("ALTER SESSION SET NLS_SORT = 'GERMAN_CI'"); +=item .. format a DateTime object for searching? + +L and L +do not take L into account, and so your L +object will not be correctly deflated into a format your RDBMS expects. + +The L method on your +storage object can be used to return the object that would normally do this, so +it's easy to do it manually: + + my $dtf = $schema->storage->datetime_parser; + my $rs = $schema->resultset('users')->search( + { + signup_date => { + -between => [ + $dtf->format_datetime($dt_start), + $dtf->format_datetime($dt_end), + ], + } + }, + ); + +With in a Result Class method, you can get this from the +L|DBIx::Class::Row/result_source>. + + my $dtf = $self->result_source->storage->datetime_parser; + +This kludge is necessary only for conditions passed to +L and L, +whereas L and L +(but not L) are +L-aware and will do the right thing when supplied +an inflated L object. =back diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 044ecfa..d56dd00 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -1669,8 +1669,8 @@ sub _gen_sql_bind { ) { carp_unique 'DateTime objects passed to search() are not supported ' . 'properly (InflateColumn::DateTime formats and settings are not ' - . 'respected.) See "Formatting DateTime objects in queries" in ' - . 'DBIx::Class::Manual::Cookbook. To disable this warning for good ' + . 'respected.) See ".. format a DateTime object for searching?" in ' + . 'DBIx::Class::Manual::FAQ. To disable this warning for good ' . 'set $ENV{DBIC_DT_SEARCH_OK} to true' }