Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registering StoreModels as ActiveModel types #170

Open
Morozzzko opened this issue May 13, 2024 · 1 comment
Open

Registering StoreModels as ActiveModel types #170

Morozzzko opened this issue May 13, 2024 · 1 comment

Comments

@Morozzzko
Copy link

I'm trying to use StoreModel as a building block for composite types.

Let's imagine I'm trying to model Money. I'm not really doing that, but it's a nice domain

Here's what I would do:

class MoneyModel
  include StoreModel::Model
 
  attribute :cents, :integer
  attribute :currency_code, :string
end

The docs suggest that I use it like this:

attribute :amount, MoneyModel.to_type

However, I feel like it's not the way I'd like to use it, as I can register my custom types

So I add that line of code:

ActiveModel::Type.register(:money, MoneyModel.to_type)

Works well so far

However, when I try to run

attribute :amount, :money 

I get a

Failure/Error: attribute :amount, :money 

NoMethodError:
  undefined method `new' for an instance of StoreModel::Types::One

Which is pretty fair considering how it all is implemented, because we can't register an instance of a type

However, the way to_type is implemented, we can't really achieve that using current representation, and it feels like we should have some way to do it

@DmitryTsepelev
Copy link
Owner

Hey!

Sounds reasonable, I'd be happy to have such feature, but sounds like a huge job to be done to achieve that 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants