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

Document new serialize columns #741

Closed
jwoertink opened this issue Jul 25, 2021 · 1 comment · Fixed by #1020
Closed

Document new serialize columns #741

jwoertink opened this issue Jul 25, 2021 · 1 comment · Fixed by #1020
Labels
guides:missing Missing documentation

Comments

@jwoertink
Copy link
Member

luckyframework/avram#695

@jwoertink jwoertink added the guides:missing Missing documentation label Jul 25, 2021
@jwoertink
Copy link
Member Author

jwoertink commented Oct 28, 2021

Just a few notes on how to use this:

class User < BaseModel
  table do
    column preferences : UserPreferences, serialize: true
  end
end

struct UserPreferences
  include JSON::Serializable
  property? receive_email : Bool = true
end

class SignUpUser < User::SaveOperation
  before_save do
    preferences.value = UserPreferences.from_json("{}")
  end
end

class UpdateUser < User::SaveOperation
  attribute allow_email : Bool
  before_save do
    prefs = preferences.value.not_nil!
    prefs.receive_email = !!allow_email.value
  end
end

user = UserQuery.new.first
user.preferences.receive_email?

As of right now, there's no special way to query against it.

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

Successfully merging a pull request may close this issue.

1 participant