jackc / surus

PostgreSQL extensions for ActiveRecord

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Include methods from model?

jemminger opened this issue · comments

Is it possible to include methods as well as columns/associations?

For example with as_json, you can include methods from the model: my_object.as_json(methods: [:this_method, :that_method]) and get back

{
  id: 1,
  name: "Foo",
  this_method: "some value",
  that_method: "another value",
  ...
}

Ah, thinking about it more I guess it's not possible, since you're retrieving straight from PG which would have no knowledge of the model's methods.

Correct. There's no way to do that without some serious hackery.