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
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Readme. Add Aliases section
  • Loading branch information
andrykonchin committed Jan 6, 2021
commit 5a7e8a63917e2488564721fa3d836f2d5ca436bb
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,26 @@ field :actions_taken, :integer, default: 0
field :joined_at, :datetime, default: -> { Time.now }
```

#### Aliases

It might be helpful to define an alias for already existing field when
naming convention used for a table differs from conventions common in
Ruby:

```ruby
field firstName, :string, alias: :first_name
```

This way there will be generated
setters/getters/`<name>?`/`<name>_before_type_cast` methods for both
original field name (`firstName`) and an alias (`first_name`).

```ruby
user = User.new(first_name: 'Michael')
user.first_name # => 'Michael'
user.firstName # => 'Michael'
```

#### Custom Types

To use a custom type for a field, suppose you have a `Money` type.
Expand Down