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 field aliases #481

Merged
merged 6 commits into from
Jan 7, 2021
Merged

Add field aliases #481

merged 6 commits into from
Jan 7, 2021

Conversation

andrykonchin
Copy link
Member

@andrykonchin andrykonchin commented Jan 6, 2021

Closes #466

Changes:

  • added alias option for the field method

Example

class User
  # ...
  field :createdAt, :datetime, alias: :created_at
end

user = User.new

user.created_at # => ...
user.created_at = Time.now
user.created_at? # => true
user.created_at_before_type_cast # => ...

Reason

It allows to generate setter/getter/<name>? and <name>_before_type_cast instance methods for specified attribute alias.

Notes

These aliases aren't supported in where conditions (e.g. you cannot use 'created_at.gt': Time.now - 1.hour - use createdAt.gt instead). Dirty API also doesn't support aliases.

@andrykonchin andrykonchin merged commit aaf2aea into master Jan 7, 2021
@andrykonchin andrykonchin deleted the add-field-aliases branch January 7, 2021 01:11
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

Successfully merging this pull request may close these issues.

Feature Request: Custom field name
1 participant