jackc / surus

PostgreSQL extensions for ActiveRecord
MIT License
395 stars 35 forks source link

Include methods from model? #36

Closed jemminger closed 6 years ago

jemminger commented 6 years ago

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",
  ...
}
jemminger commented 6 years ago

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.

jackc commented 6 years ago

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