meteor-astronomy icon indicating copy to clipboard operation
meteor-astronomy copied to clipboard

Definition of Object field & dot notation

Open rub1e opened this issue 6 years ago • 6 comments

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?

rub1e avatar Jul 06 '18 08:07 rub1e

Hi. It's hard to tell what the problem is without reproduction repository. Please, create one that only tries replicate given problem.

On Fri, Jul 6, 2018, 10:36 AM Alex Rubner [email protected] wrote:

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?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jagi/meteor-astronomy/issues/676, or mute the thread https://github.com/notifications/unsubscribe-auth/ABAKXW1B1WETcggLOJJOiJvRqZ61FPIkks5uDyF2gaJpZM4VFFlg .

lukejagodzinski avatar Jul 06 '18 08:07 lukejagodzinski

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

rub1e avatar Jul 06 '18 14:07 rub1e

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?

rub1e avatar Jul 07 '18 08:07 rub1e

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

lukejagodzinski avatar Jul 07 '18 09:07 lukejagodzinski

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

rub1e avatar Jul 07 '18 10:07 rub1e

@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.

lukejagodzinski avatar Jul 08 '18 08:07 lukejagodzinski