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=a3fe023972d9c7179f9d0c01bb948f8da3b4f3c5;hpb=f4db0d9033ae99351ca6cdd3de973a13fe08acaa;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/Manual/FAQ.pod b/lib/DBIx/Class/Manual/FAQ.pod index a3fe023..bcdde3a 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 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