How to add virtual fields in model

I want to add virtual fields in a model.

table: field1 field2
I want to add field3 which is field1*2 + field2

I know tihs can be achieved in View, but I want it in model.
Then I will pass this model to PagerRenderer to paginate.

How to achieve this?

thanks

Superbiji wrote:

I want to add virtual fields in a model.

table: field1 field2
I want to add field3 which is field1*2 + field2

I know tihs can be achieved in View, but I want it in model.
Then I will pass this model to PagerRenderer to paginate.

How to achieve this?

thanks

In your model…

def field3
field1 + field2
end

Something like the following should work just fine:

class YourModel

def field3
field1 * 2 + field2
end
end

As for rendering the list. It should paginate fine - but you might not
be
able to use the standard way of determining which columns will be
rendered
(I don’t think it will pick up your “virtual field”). Someone with more
experience could chime in here.

Cheers,
Pete.

Kevin O. wrote:

def field3
field1 + field2
end

@pages, @items = ctx.paginate tablename, opt

I’ve did that, but my field3 does not shown in @items

Peter S. wrote:

As for rendering the list. It should paginate fine - but you might not
be
able to use the standard way of determining which columns will be
rendered

My PagerRenderer is dumb renderer, which I will use for all my model. It
iterates model’s columns using @items[0].class.content_columns