-
Notifications
You must be signed in to change notification settings - Fork 550
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
Feedback requested for accessing property values #25
Comments
Agree with you we should be permissive, unless we do something like registering kinds (as proposed in googleapis/google-cloud-node#157), and then we'd want to enforce a schema. |
/cc @GoogleCloudPlatform/cloud-datastore |
The next version of the API will have an explicit null value. So something to consider is that if entity[...] returns nil, there will be no way to distinguish between a set null value and a missing value. |
For the past month or so I've been thinking about differentiating between and entity not having a property vs. having a property with a NULL value. Closely related is how to remove a property from an entity vs. setting the property's value to NULL. First, a bit of background. Currently the Entity has a entity["name"] = "Mike"
entity["email"] = "[email protected]"
entity.properties #=> [["name", "Mike"], ["email", "[email protected]"]]
entity.properties.clear #=> []
entity.properties #=> [["name", "Mike"], ["email", "[email protected]"]] I'd like to change entity["name"] = "Mike"
entity["email"] = "[email protected]"
entity.properties #=> {"name" => "Mike", "email" => "[email protected]"}
# Check for a property that exists
entity.properties.exist? "name" #=> true
entity["name"] #=> "Mike"
entity.properties["name"] #=> "Mike"
# Check for a property that does not exist
entity.properties.exist? "age" #=> false
entity["age"] #=> nil
entity.properties["age"] #=> nil
# Deleting a property
entity.properties.exist? "email" #=> true
entity.properties.delete "email"
entity.properties.exist? "email" #=> false
entity.properties #=> {"name" => "Mike"} Here is the my proposed API for this new property object:
This object would also be responsible for normalizing keys to make sure they were always stored as strings but could be accessed as symbols. entity[:name] = "Mike"
entity[:email] = "[email protected]"
entity.properties.exist? :name #=> true
entity.properties.exist? "name" #=> true
entity.properties #=> {"name" => "Mike", "email" => "[email protected]"} In the future I can also see this object being responsible for dirty tracking changes, so we don't have to update every property when saving an entity, only the properties that changed. This would be API-compatible with ActiveModel's dirty tracking. Thoughts? |
👍 from me. |
Please see #62. |
How should Datastore's Entity behave when accessing properties that have not yet been set?
The current behavior is to return
nil
. Another option is to raise an error.IMO the behavior should be permissive. Consider the case of a projection query where entity records stored in Datastore have both name and email, but only name is projected in the query. In ActiveRecord the attributes that are not selected are set to
nil
.Thoughts?
The text was updated successfully, but these errors were encountered: