# datastoreEntity()

In case you need at any moment to fetch the entity **data** from Google Datastore, this method will do just that right on the entity instance. It is useful for example in "pre" delete hooks where the entity to be deleted is passed but we don't have its data.

```javascript
// user.model.js

const userSchema = new Schema({ name: { type: String }, pictIdx: { type: Number });

schema.pre('delete', function() {
    // The scope "this" is the entity to be deleted.
    // At this stage we don't have its data but we need it in order
    // to check if there is an Image to delete with the User.
    // We use datastoreEntity() for that.

    return this.datastoreEntity().then(entity => {
        if (!entity.pictIdx) {
            return;
        }
        // We delete the associate image entity
        return entity.model('Image').delete(entity.entity.pictIdx);
    });
});

module.exports = gstore.model('User', userSchema);

// ...

// Now each time we delete a User, we'll delete any Image associated with it.

const User = require('user.model');
User.delete(123).then(...);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sebloix.gitbook.io/gstore-node/v8.x/entity/methods/datastoreentity.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
