krainboltgreene / jsonapi-realizer.rb

Turn JSON:API requests into real records

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Virtual attributes

bronsonholden opened this issue · comments

Hey @krainboltgreene, I've got a feature idea I'd like to run by you. I want to add support for "virtual" attributes, i.e. they're not persisted in a database column for that model. My current use case is a state attribute that is delegated to a different model, and so causes an attribute write error when passed to the realizer. I'm not fully convinced it'll be common enough to require built-in support, but I'm still nurturing the idea.

My workaround at this point is to extract the data for that virtual attribute before passing the params hash to the realizer, but it'd be nice if I could select certain attributes for it to silently ignore.

Thoughts?

So I've done this a few times and each time I end up thinking:

Are virtual attributes the job of this gem? Really, shouldn't the job of the gem simply be to decide which properties are exposed?

Anyways, that's where I'm currently at.

Yeah this is probably a non-issue. I just turned my brain on and used attr_accessor on the model in question. Much cleaner this way.