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

Declare nested fields #258

Open
sayuj opened this issue Mar 4, 2020 · 2 comments
Open

Declare nested fields #258

sayuj opened this issue Mar 4, 2020 · 2 comments
Labels
feature New functionalities

Comments

@sayuj
Copy link

sayuj commented Mar 4, 2020

I have a document like:

{
  "first_name": "First Name",
  "last_name": "Last Name",
  "birth": {
    "place": "Place of birth",
    "date": "Date of birth"
  }
}

I would like to declare the field birth["date"] as Date type. How can I do that?

@zedtux
Copy link
Collaborator

zedtux commented Mar 13, 2020

Nobrainer is not supporting this use case. From the roadmap:

Support embedded documents. Embedding should be done by using the type system like regular fields.

You can declare the birth field as a Hash but you can't control the data type within the hash.

There is another way of doing it, which is of using a Birth model and adding a has_one :birth to your current model. Then the Birth model can describe the fields and their types.

Hope this help :)

@sayuj
Copy link
Author

sayuj commented Mar 17, 2020

@zedtux Thank you for your response.

Multiple documents would not be a perfect fit. I'm glad the use cases there on the roadmap.

@zedtux zedtux added the feature New functionalities label Feb 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionalities
Projects
None yet
Development

No branches or pull requests

2 participants