Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

Include updated_at and created_at with results() #67

Open
chriship opened this issue Mar 28, 2020 · 2 comments
Open

Include updated_at and created_at with results() #67

chriship opened this issue Mar 28, 2020 · 2 comments

Comments

@chriship
Copy link

Is it possible to retreive the created_at and updated_at timestamps with the results call?

At the moment I have a relationship between 2 models and am retrieving them like so:

$project = $projectsDb->get($id);   
$prices = $pricesDb->where('project_id','=',$id)->results();
$project->prices = $prices;

But doing it like this means that $project->prices does not have the timestamps.

@timothymarois
Copy link
Member

Hi,

On the request of get() you can then call $pricesDB->createdAt() and $pricesDb->updatedAt()

The queries are meant to find documents itself, query reference, but you can create custom filters to query within a document, I would recommend if using Laravel, push your entire document data into a collection object if you want the use of collection methods.

@joemottershaw
Copy link

joemottershaw commented Apr 3, 2020

I feel created_at and updated_at should be included by default? A lot of the queries are going to be done using the results() or first() methods and at that point you've lost 2 important fields that you will probably want access to.

Say you wanted to query all users with the name Joe and display all of their records:

$users = $usersDb->query('name', '=', 'Joe')->results();

That would return an array but only with the fields I specified when storing it, I couldn't get, for example, their created at date (which could represent their registered date) in that one line of code, if I want to get those timestamps as well as the standard user fields, I have to do this:

$users = $usersDb->query('name', '=', 'Joe')->results();

$actualUsers = [];

foreach ($users as $user) {
    $actualUser = $usersDb->get($user['id']);

    $actualUsers[] = [
        'id' => $actualUser->field('id'),
        'name' => $actualUser->field('name'),
        'email' => $actualUser->field('email'),
        'createdAt' => $actualUser->createdAt(),
        'updatedAt' => $actualUser->updatedAt()
    ];
}

var_dump($actualUsers);

That would give me an array with the fields and the timestamps that I would expect, but it just seems like a lot of extra leg work to get something that is stored along side the same data? That code is untested by the way and this is irrelevant to Laravel/Collections.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants