parse.com-php-library icon indicating copy to clipboard operation
parse.com-php-library copied to clipboard

what about column with type "object" ?

Open alonam-zz opened this issue 11 years ago • 11 comments

I want to update a column of type "object" in my table, with: {"0":{"end":"1:00","start":"12:00"}, "1":{"end":"1:00","start":"12:00"}, "2":{"end":"1:00","start":"12:00"}, "3":{"end":"1:00","start":"12:00"}, "4":{"end":"1:00","start":"12:00"}, "5":{"end":"1:00","start":"12:00"}, "6":{"end":"1:00","start":"12:00"}}

but every time I get error like: "invalid type for key ....., expected object, but got string" (if I use json_encode) or " invalid type for key ....., expected object, but got array"..

HELP PLEASE!!!!

:)

alonam-zz avatar Apr 02 '13 14:04 alonam-zz

Could you provide some php code so we can help figure out why this is not working?

andrewscofield avatar Apr 02 '13 15:04 andrewscofield

Hi!

I mean: If i want to set my column to {"0":{"end":"10:00","start":"17:00"}, "1":{"end":"12:00","start":"15:00"}}

it should be created like dictionary..I guess..so I use arrays:

$openeing_hours["0"] = array ("start"=>"10:00:","end"=>"17:00"); $openeing_hours["1"] = array ("start"=>"12:00:","end"=>"15:00"); $openeing_hours = json_encode($openeing_hours);

$parse = new parseObject("Store"); $parse->__set("opening_hours",$opening_hours); <------this fails. Column is "Object". What should I send here instead?

(parse.com error: invalid type for key opening_hours, expected object, but got string)

Just to mention, I'm not the owner of the DB, so I really can't change the column type.

Thanks.

Alona

alonam-zz avatar Apr 02 '13 15:04 alonam-zz

I too am interested in this. I need to add misc data to a row so I added a column of type object to handle it, but apparently this library doesn't like doing as alonam has suggested.

thedangler avatar Apr 02 '13 20:04 thedangler

That's strang because I saw one friend of mine, using Python...and succesfully updated object type with JSON..so I don't get it..If someone knows the answer...it may help a lot!

BTW, in linux it should be :$opening_hours = json_encode($opening_hours,JSON_FORCE_OBJECT); to let it be non associative array as object...

alonam-zz avatar Apr 02 '13 21:04 alonam-zz

Hey @alonam, my library is actually already running json_encode on things, so this could be the problem. Can you try just setting opening_hours to be just your array?

andrewscofield avatar Apr 02 '13 21:04 andrewscofield

Already tried it.. that give's me the error: parse.com error: invalid type for key opening_hours, expected object, but got array (if I leave the array as it is, with no json_encode...)

SO...I now tried to change your line : $postData = json_encode($args['data']); ----> $postData = json_encode($args['data'],JSON_FORCE_OBJECT); and..IT WORKS! But...only for objects type...for columns of array type..it fails. Now I really don't know what to do.

alonam-zz avatar Apr 02 '13 21:04 alonam-zz

@alonam that means I need to make a change in the library to account for this.

andrewscofield avatar Apr 02 '13 22:04 andrewscofield

Thanks...maybe in the meantime I'll ask for changing the col to array..Hope it's not too complicated...

alonam-zz avatar Apr 03 '13 00:04 alonam-zz

A work around for now is to make your column type array then you can make the first index an object and it works fine.

$parse->something = array('{test:2}');

It's what I'm doing until it has been resolved.

M

thedangler avatar Apr 03 '13 17:04 thedangler

Great to hear, I'll still keep this on my radar to get both arrays and object types working correctly.

andrewscofield avatar Apr 03 '13 18:04 andrewscofield

hi.. Unfortunately, I can't change the column type...because android app already uses the parse table.. So until the change of your API, I'll make another workaround outside the library...(only for save and update..).

thanks @thedangler @apotropaic

alonam-zz avatar Apr 03 '13 18:04 alonam-zz