Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DBIx Class Row virtual/non-persistent columns

Is it possible to add columns to a DBIx::Class::Row object that are virtual in that they are not saved to the database? I am looking for functionality like Rose::DB::Object provides through its non-persistent columns http://search.cpan.org/dist/Rose-DB-Object/lib/Rose/DB/Object/Metadata.pm#nonpersistent_columns

like image 545
Bestfoodnearme.com Avatar asked Mar 01 '26 13:03

Bestfoodnearme.com


2 Answers

Have you tried adding methods to the Result classes in your Schema? That might get you to the same place. The methods you add can't be used in ->search and won't be returned in ->get_columns, but depending on your use case, it may be enough.

like image 139
oalders Avatar answered Mar 03 '26 02:03

oalders


I just had to look this up again as I had a need for it. You've probably got a solution already, but for others that come here looking: https://metacpan.org/module/DBIx::Class::Manual::FAQ#Misc

Basically either use Moose and create an attribute, or add something like this to your schema:

__PACKAGE__->mk_group_accessors('simple' => qw/non_column_data/); # must use simple group
like image 37
kbosak Avatar answered Mar 03 '26 03:03

kbosak