X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FManual%2FFAQ.pod;h=bcdde3a5e78dfe8bd37aec55843ed946a9e3a945;hb=228d5eae483427447ab808dee3f955a4d2ed0801;hp=a50865c0da2954e04e40dc8c019f74add5599c5e;hpb=838ef78d24f66da1c2d45a88495fe40bfe8ee522;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/Manual/FAQ.pod b/lib/DBIx/Class/Manual/FAQ.pod index a50865c..bcdde3a 100644 --- a/lib/DBIx/Class/Manual/FAQ.pod +++ b/lib/DBIx/Class/Manual/FAQ.pod @@ -77,7 +77,7 @@ lot later. =item .. tell DBIx::Class about relationships between my tables? -There are a vareity of relationship types that come pre-defined for +There are a variety of relationship types that come pre-defined for you to use. These are all listed in L. If you need a non-standard type, or more information, look in L. @@ -113,12 +113,19 @@ as you like. See L. Read the documentation on L. -=item .. stop DBIx::Class from attempting to cascade deletes on my has_many relationships? +=item .. stop DBIx::Class from attempting to cascade deletes on my has_many and might_have relationships? By default, DBIx::Class cascades deletes and updates across -C relationships. If your database already does this (and -that is probably better), turn it off by supplying C<< cascade_delete => 0 >> -in the relationship attributes. See L. +C and C relationships. You can disable this +behaviour on a per-relationship basis by supplying +C<< cascade_delete => 0 >> in the relationship attributes. + +The cascaded operations are performed after the requested delete or +update, so if your database has a constraint on the relationship, it +will have deleted/updated the related records or raised an exception +before DBIx::Class gets to perform the cascaded operation. + +See L. =item .. use a relationship? @@ -258,6 +265,18 @@ its SQL searches. So if you fail to find help in the L, try looking in the SQL::Abstract documentation. +=item .. make searches in Oracle (10gR2 and newer) case-insensitive? + +To make Oracle behave like most RDBMS use on_connect_do to issue +alter session statements on database connection establishment: + + ->on_connect_do("ALTER SESSION SET NLS_COMP = 'LINGUISTIC'"); + ->on_connect_do("ALTER SESSION SET NLS_SORT = '_CI'"); + e.g. + ->on_connect_do("ALTER SESSION SET NLS_SORT = 'BINARY_CI'"); + ->on_connect_do("ALTER SESSION SET NLS_SORT = 'GERMAN_CI'"); + + =back =head2 Fetching data @@ -294,11 +313,11 @@ way to get that single row is to first run your search as usual: Then call L and ask it only to return 1 row: - ->slice(0,1) + ->slice(0) These two calls can be combined into a single statement: - ->search->(undef, { order_by => "id DESC" })->slice(0,1) + ->search->(undef, { order_by => "id DESC" })->slice(0) Why slice instead of L or L? If supported by the database, slice will use LIMIT/OFFSET to hint to the database that we @@ -357,6 +376,19 @@ scalar reference: ->update({ somecolumn => \'othercolumn' }) +But note that when using a scalar reference the column in the database +will be updated but when you read the value from the object with e.g. + + ->somecolumn() + +you still get back the scalar reference to the string, B the new +value in the database. To get that you must refresh the row from storage +using C. Or chain your function calls like this: + + ->update->discard_changes + + to update the database and refresh the object in one step. + =item .. store JSON/YAML in a column and have it deflate/inflate automatically? You can use L to accomplish YAML/JSON storage transparently. @@ -396,6 +428,41 @@ data out. You can add your own data accessors to your classes. +One method is to use the built in mk_group_accessors (via L) + + package MyTable; + + use parent 'DBIx::Class'; + + __PACKAGE__->table('foo'); #etc + __PACKAGE__->mk_group_accessors('simple' => qw/non_column_data/); # must use simple group + +An another method is to use L with your L package. + + package MyTable; + + use Moose; # import Moose + use Moose::Util::TypeConstraint; # import Moose accessor type constraints + + extends 'DBIx::Class'; # Moose changes the way we define our parent (base) package + + has 'non_column_data' => ( is => 'rw', isa => 'Str' ); # define a simple attribute + + __PACKAGE__->table('foo'); # etc + +With either of these methods the resulting use of the accesssor would be + + my $row; + + # assume that some where in here $row will get assigned to a MyTable row + + $row->non_column_data('some string'); # would set the non_column_data accessor + + # some other stuff happens here + + $row->update(); # would not inline the non_column_data accessor into the update + + =item How do I use DBIx::Class objects in my TT templates? Like normal objects, mostly. However you need to watch out for TT