Permalink
Browse files

Merge 'trunk' into 'DBIx-Class-current'

r20551@brandon-blacks-computer (orig r3005):  castaway | 2007-01-05 03:25:11 -0600
add inflatecolumn fixes to Changes

r20553@brandon-blacks-computer (orig r3007):  castaway | 2007-01-09 15:20:55 -0600
todoify collapse test

r20554@brandon-blacks-computer (orig r3008):  castaway | 2007-01-09 15:42:59 -0600
Up version to 0.07004

r20555@brandon-blacks-computer (orig r3009):  castaway | 2007-01-09 15:44:39 -0600
0.07004

r20556@brandon-blacks-computer (orig r3010):  castaway | 2007-01-10 11:54:19 -0600
Skip .orig files in dist

r20557@brandon-blacks-computer (orig r3011):  castaway | 2007-01-10 13:37:23 -0600
oops, remove .orig files etc

r20599@brandon-blacks-computer (orig r3053):  zarquon | 2007-01-23 04:15:05 -0600
minor doc improvement to clarify how to do joins
r20604@brandon-blacks-computer (orig r3058):  zarquon | 2007-01-24 15:48:07 -0600
explained a cryptic error message
r20610@brandon-blacks-computer (orig r3064):  castaway | 2007-01-29 10:28:12 -0600
Make POD a little more obvious about component order
 --This line, and those below, will be ignored--

M    DateTime.pm

r20616@brandon-blacks-computer (orig r3070):  jester | 2007-01-31 17:59:06 -0600
Doc cleanup in Ordered.pm
r20618@brandon-blacks-computer (orig r3072):  castaway | 2007-02-02 13:48:53 -0600
POD updates

r20619@brandon-blacks-computer (orig r3073):  ash | 2007-02-03 15:33:19 -0600
Made ->update not change the hashref passed in (with test.)
r20621@brandon-blacks-computer (orig r3075):  ash | 2007-02-05 06:29:52 -0600
Backed out my r3073, and doc'd the fact that it takes a hashref that might be changed
r20622@brandon-blacks-computer (orig r3076):  castaway | 2007-02-05 07:56:35 -0600
Add _accessor example, thanks to grinktt3n

r20623@brandon-blacks-computer (orig r3077):  castaway | 2007-02-05 08:23:22 -0600
Fix overload example

r20625@brandon-blacks-computer (orig r3079):  grink1tt3n | 2007-02-06 13:40:00 -0600
Added;
	FAQ-fetch-a-formatted-column.txt
	FAQ-store-JSON-in-a-column.txt


r20640@brandon-blacks-computer (orig r3094):  castaway | 2007-02-08 02:25:54 -0600
Argh! Fix spurious example

r20643@brandon-blacks-computer (orig r3097):  castaway | 2007-02-13 08:00:21 -0600
Improve resultset_attributes docs

r20644@brandon-blacks-computer (orig r3098):  grink1tt3n | 2007-02-14 01:16:40 -0600
Fleshed out the JSON inflated column example with a corresponding YAML example. Added a cautionary warning against overuse. Added a link to InflateColumn.


r20645@brandon-blacks-computer (orig r3099):  grink1tt3n | 2007-02-14 02:39:26 -0600
Added how to '.. fetch a single (or topmost) row?' to the FAQ


r20646@brandon-blacks-computer (orig r3100):  zarquon | 2007-02-14 02:44:18 -0600
improved docs for as attrib
r20647@brandon-blacks-computer (orig r3101):  zarquon | 2007-02-14 04:05:51 -0600
pointed out ambiguity of as attribs
r26909@brandon-blacks-computer (orig r3107):  castaway | 2007-03-03 06:15:03 -0600
Fix to $filename from Carl Vincent

r27114@brandon-blacks-computer (orig r3126):  jshirley | 2007-03-12 16:27:08 -0500
Updating Manual/Intro to reflect better -in => [] usage, adding myself to contributors (mst put me in dbic-devel, too)
r27116@brandon-blacks-computer (orig r3128):  castaway | 2007-03-14 10:02:44 -0500
Added patch from Schwern to allow cdbi compat to infer the has_many from a has_a

r27119@brandon-blacks-computer (orig r3129):  castaway | 2007-03-16 11:04:07 -0500
Initial version of Manual::Joining

r27120@brandon-blacks-computer (orig r3130):  castaway | 2007-03-16 11:06:21 -0500
Add FAQ and Joining links to Manual.pod

r27319@brandon-blacks-computer (orig r3148):  blblack | 2007-03-29 08:42:27 -0500
fix for rt.cpan.org #25683 (DBD::Sybase/FreeTDS/MSSQL cannot have two open sths during column_info
r27324@brandon-blacks-computer (orig r3153):  blblack | 2007-03-29 09:13:17 -0500
backport Ash's quoting fix from Loader to columns_info_for
r29666@brandon-blacks-computer (orig r3173):  castaway | 2007-04-02 17:19:05 -0500
Add patch from dec to allow us to pick which sources to deploy

r30330@brandon-blacks-computer (orig r3185):  matthewt | 2007-04-09 15:41:34 -0500
add SQL::Abstract to search docs (patch from zamolxes)
r30510@brandon-blacks-computer (orig r3189):  blblack | 2007-04-13 19:09:32 -0500
fixed regex in t/76joins (was relying on a 5.8.8 bug that is fixed in bleadperl, so this test was failing on bleadperl)
r30560@brandon-blacks-computer (orig r3196):  marcus | 2007-04-16 07:55:44 -0500
Updated cookbook example
r30589@brandon-blacks-computer (orig r3199):  blblack | 2007-04-17 18:45:11 -0500
Changes list synced up through now
r30590@brandon-blacks-computer (orig r3200):  blblack | 2007-04-17 18:47:03 -0500
cleared up a Changes entry
r30591@brandon-blacks-computer (orig r3201):  blblack | 2007-04-17 19:21:01 -0500
0.07006 changes, version update
r30607@brandon-blacks-computer (orig r3202):  matthewt | 2007-04-18 21:29:05 -0500
reverting r3173, already implemented in -current
r30709@brandon-blacks-computer (orig r3208):  matthewt | 2007-04-24 17:04:02 -0500
oops. props to chapman for the spot
r30762@brandon-blacks-computer (orig r3220):  blblack | 2007-05-01 00:25:33 -0500
load-time performance improvements
  • Loading branch information...
2 parents 36d18cd + 5c46030 commit ca83d811f3ce60ebb819ce9ad54179837f6157c6 @blblack blblack committed May 1, 2007
View
39 Changes
@@ -9,6 +9,14 @@ Revision history for DBIx::Class
is_foreign_key_constrain to allow explicit control over wether or
not a foreign constraint is needed
+0.07006 2007-04-17 23:18:00
+ - Lots of documentation updates
+ - deploy now takes an optional 'source_names' parameter (dec)
+ - Quoting for for columns_info_for
+ - RT#25683 fixed (multiple open sths on DBD::Sybase)
+ - CDBI compat infers has_many from has_a (Schwern)
+ - Fix ddl_filename transformation (Carl Vincent)
+
0.07999_02 2007-01-25 20:11:00
- add support for binding BYTEA and similar parameters (w/Pg impl)
- add support to Ordered for multiple ordering columns
@@ -18,6 +26,24 @@ Revision history for DBIx::Class
- Changed row and rs objects to not have direct handle to a source,
instead a (schema,source_name) tuple of type ResultSourceHandle
+0.07005 2007-01-10 18:36:00
+ - fixup changes file
+ - remove erroneous .orig files - oops
+
+0.07004 2007-01-09 21:52:00
+ - fix find_related-based queries to correctly grep the unique key
+ - fix InflateColumn to inflate/deflate all refs but scalar refs
+
+0.07003 2006-11-16 11:52:00
+ - fix for rt.cpan.org #22740 (use $^X instead of hardcoded "perl")
+ - Tweaks to resultset to allow inflate_result to return an array
+ - Fix UTF8Columns to work under Perl <= 5.8.0
+ - Fix up new_result in ResultSet to avoid alias-related bugs
+ - Made new/update/find handle 'single' rel accessor correctly
+ - Fix NoBindVars to be safer and handle non-true bind values
+ - Don't blow up if columns_info_for returns useless results
+ - Documentation updates
+
0.07999_01 2006-10-05 21:00:00
- add connect_info option "disable_statement_caching"
- create insert_bulk using execute_array, populate uses it
@@ -41,19 +67,6 @@ Revision history for DBIx::Class
These accessors no longer automatically require the classes when
set.
-0.07004
- - fix find_related-based queries to correctly grep the unique key
-
-0.07003 2006-11-16 11:52:00
- - fix for rt.cpan.org #22740 (use $^X instead of hardcoded "perl")
- - Tweaks to resultset to allow inflate_result to return an array
- - Fix UTF8Columns to work under Perl <= 5.8.0
- - Fix up new_result in ResultSet to avoid alias-related bugs
- - Made new/update/find handle 'single' rel accessor correctly
- - Fix NoBindVars to be safer and handle non-true bind values
- - Don't blow up if columns_info_for returns useless results
- - Documentation updates
-
0.07002 2006-09-14 21:17:32
- fix quote tests for recent versions of SQLite
- added reference implementation of Manual::Example
View
@@ -41,5 +41,8 @@
# Skip maint stuff
^maint/
+# Avoid copies to .orig
+\.orig$
+
# Dont use Module::Build anymore
# Build.PL
View
@@ -217,6 +217,8 @@ jesper: Jesper Krogh
jguenther: Justin Guenther <jguenther@cpan.org>
+jshirley: J. Shirley <jshirley@gmail.com>
+
konobi: Scott McWhirter
LTJake: Brian Cassidy <bricas@cpan.org>
@@ -20,6 +20,12 @@ sub has_many {
$args->{cascade_delete} = 0;
}
+ if( !$f_key and !@f_method ) {
+ my $f_source = $f_class->result_source_instance;
+ ($f_key) = grep { $f_source->relationship_info($_)->{class} eq $class }
+ $f_source->relationships;
+ }
+
$class->next::method($rel, $f_class, $f_key, $args);
if (@f_method) {
@@ -33,8 +33,7 @@ sub inject_base {
# it on the basis of the comments in Class::C3, the author was on #dbix-class
# while I was implementing this.
- my $table = { Class::C3::_dump_MRO_table };
- eval "package $target; import Class::C3;" unless exists $table->{$target};
+ eval "package $target; import Class::C3;" unless exists $Class::C3::MRO{$target};
}
sub load_components {
@@ -14,7 +14,7 @@ Load this component and then declare one or more
columns to be of the datetime, timestamp or date datatype.
package Event;
- __PACKAGE__->load_components(qw/InflateColumn::DateTime/);
+ __PACKAGE__->load_components(qw/Core InflateColumn::DateTime/);
__PACKAGE__->add_columns(
starts_when => { data_type => 'datetime' }
);
@@ -33,7 +33,7 @@ one your code should continue to work without modification (though note
that this feature is new as of 0.07, so it may not be perfect yet - bug
reports to the list very much welcome).
-For more help with components, see L<DBIx::Class::Manual::Component>.
+For more help with using components, see L<DBIx::Class::Manual::Component/USING>.
=cut
@@ -11,6 +11,10 @@ from your SQL database.
=head1 SECTIONS
+=head2 L<DBIx::Class::Manual::FAQ>
+
+Short answers and doc pointers to questions.
+
=head2 L<DBIx::Class::Manual::Intro>
Beginner guide to using DBIx::Class.
@@ -19,6 +23,10 @@ Beginner guide to using DBIx::Class.
An example of slightly more complex usage.
+=head2 L<DBIx::Class::Manual::Joining>
+
+How to translate known SQL JOINs into DBIx-Class-ish.
+
=head2 L<DBIx::Class::Manual::Cookbook>
Convenient recipes for DBIC usage.
@@ -107,12 +107,15 @@ to access the returned value:
);
# Equivalent SQL:
- # SELECT name name, LENGTH( name ) name_length
+ # SELECT name name, LENGTH( name )
# FROM artist
-If your alias exists as a column in your base class (i.e. it was added
-with C<add_columns>), you just access it as normal. Our C<Artist>
-class has a C<name> column, so we just use the C<name> accessor:
+Note that the C< as > attribute has absolutely nothing to with the sql
+syntax C< SELECT foo AS bar > (see the documentation in
+L<DBIx::Class::ResultSet/ATTRIBUTES>). If your alias exists as a
+column in your base class (i.e. it was added with C<add_columns>), you
+just access it as normal. Our C<Artist> class has a C<name> column, so
+we just use the C<name> accessor:
my $artist = $rs->first();
my $name = $artist->name();
@@ -139,7 +142,7 @@ any of your aliases using either of these:
select => [
{ distinct => [ $source->columns ] }
],
- as => [ $source->columns ]
+ as => [ $source->columns ] # remember 'as' is not the same as SQL AS :-)
}
);
@@ -176,6 +179,10 @@ L<DBIx::Class> supports C<GROUP BY> as follows:
# LEFT JOIN cd cds ON ( cds.artist = me.artistid )
# GROUP BY name
+Please see L<DBIx::Class::ResultSet/ATTRIBUTES> documentation if you
+are in any way unsure about the use of the attributes above (C< join
+>, C< select >, C< as > and C< group_by >).
+
=head3 Predefined searches
You can write your own L<DBIx::Class::ResultSet> class by inheriting from it
@@ -415,7 +422,7 @@ ways, the obvious one is to use search:
{},
{
select => [ { sum => 'Cost' } ],
- as => [ 'total_cost' ],
+ as => [ 'total_cost' ], # remember this 'as' is for DBIx::Class::ResultSet not SQL
}
);
my $tc = $rs->first->get_column('total_cost');
@@ -526,7 +533,7 @@ in the future.
=head2 Many-to-many relationships
-This is straightforward using L<DBIx::Class::Relationship::ManyToMany>:
+This is straightforward using L<ManyToMany|DBIx::Class::Relationship/many_to_many>:
package My::DB;
# ... set up connection ...
@@ -568,7 +575,9 @@ C<next::method>.
$attrs->{foo} = 'bar' unless defined $attrs->{foo};
- $class->next::method($attrs);
+ my $new = $class->next::method($attrs);
+
+ return $new;
}
For more information about C<next::method>, look in the L<Class::C3>
@@ -586,7 +595,7 @@ module.
To make an object stringify itself as a single column, use something
like this (replace C<foo> with the column/method of your choice):
- use overload '""' => 'foo', fallback => 1;
+ use overload '""' => sub { shift->name}, fallback => 1;
For more complex stringification, you can use an anonymous subroutine:
@@ -1122,4 +1131,43 @@ Just use C<find_or_new> instead, then check C<in_storage>:
# do whatever else you wanted if it was a new row
}
+=head3 Wrapping/overloading a column accessor
+
+Problem: Say you have a table "Camera" and want to associate a description
+with each camera. For most cameras, you'll be able to generate the description from
+the other columns. However, in a few special cases you may want to associate a
+custom description with a camera.
+
+Solution:
+
+In your database schema, define a description field in the "Camera" table that
+can contain text and null values.
+
+In DBIC, we'll overload the column accessor to provide a sane default if no
+custom description is defined. The accessor will either return or generate the
+description, depending on whether the field is null or not.
+
+First, in your "Camera" schema class, define the description field as follows:
+
+ __PACKAGE__->add_columns(description => { accessor => '_description' });
+
+Next, we'll define the accessor-wrapper subroutine:
+
+ sub description {
+ my $self = shift;
+
+ # If there is an update to the column, we'll let the original accessor
+ # deal with it.
+ return $self->_description(@_) if @_;
+
+ # Fetch the column value.
+ my $description = $self->_description;
+
+ # If there's something in the description field, then just return that.
+ return $description if defined $description && length $descripton;
+
+ # Otherwise, generate a description.
+ return $self->generate_description;
+ }
+
=cut
@@ -255,6 +255,36 @@ Call C<get_column> on a L<DBIx::Class::ResultSet>, this returns a
L<DBIx::Class::ResultSetColumn>, see it's documentation and the
L<Cookbook|DBIx::Class::Manual::Cookbook> for details.
+=item .. fetch a formatted column?
+
+In your table schema class, create a "private" column accessor with:
+
+ __PACKAGE__->add_columns(my_common => { accessor => '_hidden_my_column' });
+
+Then, in the same class, implement a subroutine called "my_column" that
+fetches the real value and does the formatting you want.
+
+See the Cookbook for more details.
+
+=item .. fetch a single (or topmost) row?
+
+Sometimes you many only want a single record back from a search. A quick
+way to get that single row is to first run your search as usual:
+
+ ->search->(undef, { order_by => "id DESC" })
+
+Then call L<DBIx::Class::ResultSet/slice> and ask it only to return 1 row:
+
+ ->slice(0,1)
+
+These two calls can be combined into a single statement:
+
+ ->search->(undef, { order_by => "id DESC" })->slice(0,1)
+
+Why slice instead of L<DBIx::Class::ResultSet/first> or L<DBIx::Class::ResultSet/single>?
+If supported by the database, slice will use LIMIT/OFFSET to hint to the database that we
+really only need one row. This can result in a significant speed improvement.
+
=back
=head2 Inserting and updating data
@@ -296,6 +326,35 @@ scalar reference:
->update({ somecolumn => \'othercolumn' })
+=item .. store JSON/YAML in a column and have it deflate/inflate automatically?
+
+You can use L<DBIx::Class::InflateColumn> to accomplish YAML/JSON storage transparently.
+
+If you want to use JSON, then in your table schema class, do the following:
+
+ use JSON;
+
+ __PACKAGE__->add_columns(qw/ ... my_column ../)
+ __PACKAGE__->inflate_column('my_column', {
+ inflate => sub { jsonToObj(shift) },
+ deflate => sub { objToJson(shift) },
+ });
+
+For YAML, in your table schema class, do the following:
+
+ use YAML;
+
+ __PACKAGE__->add_columns(qw/ ... my_column ../)
+ __PACKAGE__->inflate_column('my_column', {
+ inflate => sub { YAML::Load(shift) },
+ deflate => sub { YAML::Dump(shift) },
+ });
+
+This technique is an easy way to store supplemental unstructured data in a table. Be
+careful not to overuse this capability, however. If you find yourself depending more
+and more on some data within the inflated column, then it may be time to factor that
+data out.
+
=back
=head2 Misc
@@ -356,7 +356,7 @@ L<SQL::Abstract> construct to C<search>:
my $rs = $schema->resultset('Album')->search({
artist => { '!=', 'Janis Joplin' },
year => { '<' => 1980 },
- albumid => [ 1, 14, 15, 65, 43 ]
+ albumid => { '-in' => [ 1, 14, 15, 65, 43 ] }
});
This results in something like the following C<WHERE> clause:
Oops, something went wrong.

0 comments on commit ca83d81

Please sign in to comment.