From: Jason M. Mills Date: Fri, 30 Jan 2009 01:37:01 +0000 (+0000) Subject: Added a more verbose non column accessor example. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b7875f2bb94b758c2e99f5d7733e488ad1fc2302;p=dbsrgits%2FDBIx-Class-Historic.git Added a more verbose non column accessor example. --- diff --git a/lib/DBIx/Class/Manual/FAQ.pod b/lib/DBIx/Class/Manual/FAQ.pod index a3fe023..a539be8 100644 --- a/lib/DBIx/Class/Manual/FAQ.pod +++ b/lib/DBIx/Class/Manual/FAQ.pod @@ -428,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 her $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