CodeIgniter computed column in model
Is it possible to add a computed column to a model in CodeIgniter? I tried
searching but didn't find much apart from
http://ellislab.com/forums/viewthread/56178/#276438 which doesn't really
solve the problem.
Basically, I have a model as follows:
namespace MyApp\Models {
class Item extends \MyApp\Models\BaseModel {
static $FIELDS = array(
'id',
'a',
'b',
);
etc....
);
I would like every model I get have an additional column, c, that can be
computed as SELECT COUNT(*) FROM items WHERE a=x where x is the current
item's a. I tried something like:
namespace MyApp\Models {
class Item extends \MyApp\Models\BaseModel {
static $FIELDS = array(
'id',
'a',
'b',
'(SELECT COUNT(*) FROM items WHERE a=item.a)',
);
etc....
);
But that doesn't work, because there is no item to reference like that. Is
there any way around this?
No comments:
Post a Comment