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

Definition of Object field & dot notation #676

Open
rub1e opened this issue Jul 6, 2018 · 6 comments
Open

Definition of Object field & dot notation #676

rub1e opened this issue Jul 6, 2018 · 6 comments

Comments

@rub1e
Copy link

rub1e commented Jul 6, 2018

Hi, I've just started playing around with this (awesome!) package and I've hit an immediate problem

I have a simple Astronomy class which I'm trying to test with the standard meteor Mocha/Chai, but I get a TypeError just when trying to save a basic document:

      const gw = new Gameweek();
      gw.save();

The error is: TypeError: Class.getFields is not a function

From this line: https://github.com/jagi/meteor-astronomy/blob/v2/lib/modules/fields/utils/castNested.js#L12

I'm really stuck and can't figure out what the issue is: any ideas?

@lukejagodzinski
Copy link
Member

lukejagodzinski commented Jul 6, 2018 via email

@rub1e
Copy link
Author

rub1e commented Jul 6, 2018

Apologies, of course, I'll provide a minimal reproduction and post it asap

@rub1e rub1e changed the title Class.getFields is not a function Definition of Object field & dot notation Jul 7, 2018
@rub1e
Copy link
Author

rub1e commented Jul 7, 2018

I figured out the issue while reproducing it, but here it is in case it helps anyone with the same problem:

https://github.com/rub1e/astro-reprod

See the README, but the issue was that I had an object field that I defined like this:

fields: {
    field: Object,
    "field.subField": Number,
  }

This caused an error when I tried to save the document because it seems that you shouldn't define Object fields like this

The error disappears if you remove either one of those lines.

@lukejagodzinski I don't think this is actually a bug, but it might be an idea to mention something about dot notation in the docs - especially for people like me coming from simple-schema?

@lukejagodzinski
Copy link
Member

Maybe I will consider adding something to the docs but it's quite obvious that you can't add . to the field name because you can't do either in MongoDB. Maybe I should throw some descriptive error when somebody tries to add such a field but that would be another check that takes computational power and can make application slower

@rub1e
Copy link
Author

rub1e commented Jul 7, 2018

I understand, but I promise it wasn't obvious to me!

This is how you would do it in simple-schema

image

https://github.com/aldeed/simple-schema-js#schema-keys

I don't know if it needs a dedicated error message, but I think mentioning dot notation in the docs would be useful, because I assume most people who discover Astronomy are existing users of simple-schema?

Anyway, sorry to waste your time with an obvious error, I'll close this issue if you're happy

@lukejagodzinski
Copy link
Member

@rub1e yep I know how it's done in simple-schema. Nested classes/models should be defined in a separate "object". Take a look at GraphQL. It is even more important when your tool has the schema word in the name ;). This design decision just violates basic principles of schemas.

And no, people who discover astronomy are not only existing users of simple-schema.

However, I will add some info about field names to the documentation.

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

2 participants