modernistik / parse-stack

Parse Server Ruby Client SDK
https://www.modernistik.com/gems/parse-stack/
MIT License
61 stars 20 forks source link

Setting boolean property gives schema error #38

Closed jan-gerritsen closed 7 years ago

jan-gerritsen commented 7 years ago

I have Class InstantMessage with a boolean property 'read'. If I try to it it like this:

 @messages.each do |message|
      if message.recipient == @cn_user && message.read == false
        message.read = true
      end
    end

  @messages.save

The logger shows I send this request to Parse: {"method":"PUT","path":"/parse/classes/InstantMessage/kPceVBQF7H","body":{"read":"true"}} But this gets logged: {"code":111,"error":"schema mismatch for InstantMessage.read; expected Boolean but got String"}} Hope you can fix this. Thanks.

apersaud commented 7 years ago

It looks like the schema you've defined in your models is doesn't match the column type you have created in Parse. Have you verified what your model definition looks like and what the column type is set in your Parse Server?

jan-gerritsen commented 7 years ago

Yes. InstantMessage Class in rails:

class InstantMessage < Parse::Object
[...]
  property :read, data_type: :boolean, default: false
[...]

Schema for InstantMessage

{
    "_id" : "InstantMessage",
    "objectId" : "string",
    "updatedAt" : "date",
    "createdAt" : "date",
    "channel" : "*Channel",
    "message" : "string",
    "read" : "boolean",
    "deletedBySender" : "boolean",
    "deletedByRecipient" : "boolean",
    "channelId" : "string"
}

Sample instance in Mongo:

{
    "_id" : "1wEQk5IUUi",
    "message" : "hello",
    "read" : false,
    "_wperm" : [ 
        "*"
    ],
    "_rperm" : [ 
        "*"
    ],
    "_acl" : {
        "*" : {
            "w" : true,
            "r" : true
        }
    },
    "_created_at" : ISODate("2017-07-13T04:22:45.311Z"),
    "_updated_at" : ISODate("2017-07-13T04:22:45.311Z")
}

Note that the read property is false and not "false"

apersaud commented 7 years ago

Your model definition is incorrect. Try the following:

class InstantMessage < Parse::Object
  property :read, :boolean, default: false
end

Please also read this section carefully as boolean properties have special methods and features