Skip to content

support empty plain object as value #143

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

Closed
wants to merge 1 commit into from
Closed

Conversation

svsool
Copy link
Contributor

@svsool svsool commented Jan 12, 2017

more information you can find here https://jira.mongodb.org/browse/PHP-172

sometimes you need save empty plain object {} as value

$document->set('myValue', new stdClass);

result:

{
  myValue: {}
}

but now it always saved as ↓, because value casts to array

{
  myValue: []
}

@svsool svsool changed the title support plain object as value support empty plain object as value Jan 12, 2017
@coveralls
Copy link

coveralls commented Jan 12, 2017

Coverage Status

Coverage decreased (-0.03%) to 91.925% when pulling 11e8d02 on svsool:master into d42e2bc on sokil:master.

@svsool
Copy link
Contributor Author

svsool commented Jan 12, 2017

looks like I need fix some tests

@sokil
Copy link
Owner

sokil commented Jan 13, 2017

Tests are not the main problem. There are few other:

  1. Back compatibility, when code starts to save {} but on modify expects []
  2. Hydrating new document object with {} in field. With your code, if you save document first time, you'v got {} in db, then you read document and this field became [], because driver do not distinguish [] and {} on read from db.

So this must be done by specifying type of field, or something like that. Then hydrated and repeatedly saved document also will have {}.

By the way, why do you need {} in db, you may omit saving this field, and modilying empty field must be correctly handled.

@svsool
Copy link
Contributor Author

svsool commented Jan 14, 2017

Some legacy code may require this, but I agree with you anyway

@svsool svsool closed this Jan 14, 2017
@sokil
Copy link
Owner

sokil commented Jan 15, 2017

I.l add field type functionality snd inform you here #144

@sokil sokil reopened this Jan 15, 2017
@sokil sokil closed this Jan 15, 2017
@coveralls
Copy link

coveralls commented Jan 15, 2017

Coverage Status

Coverage decreased (-0.03%) to 91.925% when pulling 11e8d02 on svsool:master into d42e2bc on sokil:master.

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

Successfully merging this pull request may close these issues.

3 participants