Giter Site home page Giter Site logo

500 when using array type about model HOT 15 CLOSED

geddy avatar geddy commented on August 30, 2024
500 when using array type

from model.

Comments (15)

techwraith avatar techwraith commented on August 30, 2024

I'm not sure why the Array type was removed, but I believe it will work if you change type: 'array' to type: 'object'.

from model.

mde avatar mde commented on August 30, 2024

Array datatype was kind of superfluous -- and it made the round-trip serialization story simpler just to say "we have all these specific scalar datatypes, and 'object' for anything else."

This was noted in the changelog -- sorry we missed removing it from the list of documented datatypes. I just removed it, and the site should pick up the changes sometime today. Let me know if you see any other references to it floating around. :)

from model.

OscarGodson avatar OscarGodson commented on August 30, 2024

Hmm, yeah I guess I could do {ids: [123, 345]}, but how easy is that to query with Mongo or Geddy's adapter? I'm basically using this as a join. A user can have multiple IDs and why i wanted it an array.

group.id = 123 // I get the group ID from some action in the UI, like deleting the group for example
user1.groups = {ids: [123, 456, 789]} // Wrapped in an object since I can't use an array
user2.groups = {ids: [xxx, yyy, 123, zzz]}

Now, whats the easiest way to query "all users part of 123"? Or am I doing this totally wrong?

from model.

mde avatar mde commented on August 30, 2024

No, you can save any JSONizable object in that datatype. Just declare it as datatype 'object', and save the array like normal.

Any reason not to use the Postgres adapter with eager-fetched associations and do an actual join? :) That's what that's for.

from model.

techwraith avatar techwraith commented on August 30, 2024

Do this:

this.defineProperties({
  foo: {type: 'object', required: true}
});

// when setting
thing.foo = [id, otherId, etc];

Just call it an object (everything in JS is technically an object), but keep the value as an array.

from model.

techwraith avatar techwraith commented on August 30, 2024

@mde Probably because SQL sucks.

from model.

OscarGodson avatar OscarGodson commented on August 30, 2024

Ah, I see, yeah I thought object meant a hash :)

@mde I probably will later, but thats why I'm using Geddy. I can build this out as a prototype and then swap out the DB without too much fuss! (well, I hope haha)

from model.

mde avatar mde commented on August 30, 2024

@techwraith You don't have to write any SQL, that's the whole point. :)

from model.

techwraith avatar techwraith commented on August 30, 2024

@mde Well, if you only use Geddy to access the data, that's true, but if you ever have to edit data directly in the DB, that's not true. Though I suppose that's what geddy console is for.

from model.

mde avatar mde commented on August 30, 2024

NOSQL is great for things where you don't want any relationship between pieces of data. @OscarGodson is jumping through extra hoops to make non-relational data relational. If you actually want relationships between things, use a relational database. Then you can get the list of Users, the list of Groups, the list of Users per Group, and the list of Groups per Users. I keep thinking it's weird to see people a non-relational store, and then doing all these weird, hacky things to get relational behavior.

from model.

OscarGodson avatar OscarGodson commented on August 30, 2024

@mde For this it's just because I'm trying to get a prototype. I'm a noob at SQL and I've never interacted with Postgres directly. I will switch it for sure if it makes it past the prototype stage, but this is basically the only join I need to make for this stage. Geddy just allows me to plug-n-playβ„’ DBs so I can put off the SQL learning curve for a bit ;)

from model.

raphaeltm avatar raphaeltm commented on August 30, 2024

Hello.
I've got a similar, but slightly different problem.
I've got an array to be saved and it's not validating as an object. I'm not sure what other details to provide.
The exact validation error I receive is Tags: "tags" must be an object..

from model.

mde avatar mde commented on August 30, 2024

@raphaeltm Maybe we could start with a Gist of some of the problem code? Where are you setting the value for the tags prop?

from model.

raphaeltm avatar raphaeltm commented on August 30, 2024

So, I'm new to Node and Geddy and I think I figured it out.

I have a Project model with a property tags: {type: 'object'}

In the "Create" action, after var project = geddy.model.Project.create(params);, I was converting a string of comma-separated tags from the params and assigning them to project.tags, like this:

project.tags = project.tagStringToArray(project.tags);

(a method I added to the model for this purpose. it returns the array of tags.)

The PHP frameworks I've used in the past allow this sort of assignment before validation.

With Geddy, it seems that if I use project.updateProperties() instead, everything works.

Sorry if this was a bit silly. I guess it will take me a little while to figure this all out.

Thanks for the prompt response, though.

from model.

mde avatar mde commented on August 30, 2024

No worries, glad you got it figured out. :)

from model.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.