Added;
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Manual / FAQ.pod
index 30e856b..540bd21 100644 (file)
@@ -190,12 +190,12 @@ Then you can use the alias in your C<group_by> attribute.
 The first argument to C<search> is a hashref of accessor names and
 values to filter them by, for example:
 
- ->search({'created_time' => { '>=', '2006-06-01 00:00:00'} })
+ ->search({'created_time' => { '>=', '2006-06-01 00:00:00' } })
 
 Note that to use a function here you need to make the whole value into
 a scalar reference:
 
- ->search({'created_time' => \'>= yesterday() })
+ ->search({'created_time' => \'>= yesterday()' })
 
 =item .. search in several tables simultaneously?
 
@@ -205,7 +205,7 @@ then supply the name of the relationship to the C<join> attribute in
 your search, for example when searching in the Books table for all the
 books by the author "Fred Bloggs":
 
- ->search({'authors.name' => 'Fred Bloggs'}, { join => 'authors'})
+ ->search({'authors.name' => 'Fred Bloggs'}, { join => 'authors' })
 
 The type of join created in your SQL depends on the type of
 relationship between the two tables, see L<DBIx::Class::Relationship>
@@ -245,10 +245,27 @@ documentation.
 
 =over 4
 
-=item .. fetch as much data as possible in as few select calls as possible? (prefetch)
+=item .. fetch as much data as possible in as few select calls as possible?
 
 See the prefetch examples in the L<Cookbook|DBIx::Class::Manual::Cookbook>.
 
+=item .. fetch a whole column of data instead of a row?
+
+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.
+
 =back
 
 =head2 Inserting and updating data
@@ -288,7 +305,19 @@ the rows at once.
 To stop the column name from being quoted, you'll need to supply a
 scalar reference:
 
- ->update({ somecolumn => '\othercolumn'})
+ ->update({ somecolumn => \'othercolumn' })
+
+=item .. store JSON in a column and have it deflate/inflate automatically?
+
+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) },
+ });
 
 =back
 
@@ -324,3 +353,15 @@ search again or relationship accessors. The SQL query is only run when
 you ask the resultset for an actual row object.
 
 =back
+
+=head2 Notes for CDBI users
+
+=over 4
+
+=item Is there a way to make an object auto-stringify itself as a
+particular column or group of columns (a-la cdbi Stringfy column
+group, or stringify_self method) ?
+
+See L<Cookbook/Stringification>
+
+=back