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

Add metadata to options #17

Open
KirIgor opened this issue Mar 20, 2023 · 1 comment
Open

Add metadata to options #17

KirIgor opened this issue Mar 20, 2023 · 1 comment

Comments

@KirIgor
Copy link

KirIgor commented Mar 20, 2023

In some cases it would be useful to define metadata for options while initializing.

For example we can use SmartInitializer for describing relational database tables:

class Model
  include SmartCore::Initializer

  def self.column(...)
    option(...)
  end
end

class Author < Model
  column :id, Types::Integer, metadata: { primary_key: true }
  column :name, Types::String, metadata: { unique: true }
end

class Book < Model
  column :author, Types::Integer, metadata: { foreign_key: Author }
  column :title, Types::String
end

class CoveredBook < Book
  column :cover, Types::Base64Image
end

In that case some static metadata that can be inherited would be very useful.

@KirIgor
Copy link
Author

KirIgor commented Mar 21, 2023

And some way to read:

Author.__options__.first.metadata # => { primary_key: true }

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

1 participant