Skip to content
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

Read Query Handler returns null #40

Closed
controlnocontrol opened this issue May 2, 2018 · 11 comments
Closed

Read Query Handler returns null #40

controlnocontrol opened this issue May 2, 2018 · 11 comments
Labels

Comments

@controlnocontrol
Copy link

Hi there,

Great work on the Skeleton API!

I'm new to Slim API and have been playing around and have duplicated the 'todos' table with an 'entries' table. The GET routing is working fine but I can't POST anything. I get the error 'Call to a member function getTimestamp() on null'.

Debugging this leads me to $entry ($todo in your case) returning null in the following block of code (note that all handlers have been added to the dependencies file:

$command = new CreateEntryCommand($data);
$this->commandBus->handle($command);

$query = new ReadEntryQuery($data);
$entry = $this->commandBus->handle($query); // $entry returns NULL

/* Add Last-Modified and ETag headers to response. */
$response = $this->cache->withEtag($response, $entry->etag());
$response = $this->cache->withLastModified($response, $entry->timestamp());

Here's how the objects look like:

$query:
object(Skeleton\Application\Entry\ReadEntryQuery)#316 (1) {
  ["uid":"Skeleton\Application\Entry\ReadEntryQuery":private]=>
  string(13) "1E3HbNm2aHG7A"
}

$entry:
object(Skeleton\Domain\Entry)#334 (6) {
  ["uid":"Skeleton\Domain\Entry":private]=>
  NULL
  ["order":"Skeleton\Domain\Entry":private]=>
  NULL
  ["completed":"Skeleton\Domain\Entry":private]=>
  bool(false)
  ["title":"Skeleton\Domain\Entry":private]=>
  NULL
  ["createdAt":"Skeleton\Domain\Entry":private]=>
  NULL
  ["updatedAt":"Skeleton\Domain\Entry":private]=>
  NULL
}

$data:
array(3) {
  ["title"]=>
  string(25) "Testtttttttttttty the API"
  ["order"]=>
  int(10)
  ["uid"]=>
  string(13) "1E3HbNm2aHG7A"
}

When I print the $todo object in the todo POST route, I'm successfully getting data instead of NULL.

Do you have any idea why this could be the case?

@tuupola
Copy link
Owner

tuupola commented May 2, 2018

How does the migration file for entries table look like? To me it seems like the timestamp columns are not created or they are not auto updating.

@controlnocontrol
Copy link
Author

I haven't touched the migration file. I copied the todos table to the entries one using phpmyadmin. Should I be creating the entries table using the migration file? Is there a way not to do so?

@tuupola
Copy link
Owner

tuupola commented May 2, 2018

Using PHPMyAdmin look at the entries table you created. Are the timestamps created and do they have meaningful values, ie are the created_at and updated_at columns there and do they have values or are they null?

@controlnocontrol
Copy link
Author

Yes all the timestamps look okay and they are exactly as the todos table was.

@controlnocontrol
Copy link
Author

I've also created new entryRepository and ZendEntryRepository classes that's used for the handlers in the commandBus.

@tuupola
Copy link
Owner

tuupola commented May 2, 2018

Ok. It seems data from database is not hydrated into the Entry object. Look at the ZendEntryRepository and EntryHydratorFactory you have created and compare them to the working Todo ones from the skeleton.

@controlnocontrol
Copy link
Author

Thanks. They're virtually the same except that all Todo and todo strings were replaced with Entry and entry.

Any other suggestions?

Thanks so far BTW. You're great!

@controlnocontrol
Copy link
Author

I've rerun the migration and added the entries table, which is exactly the same as todos except for the table name.

Now I'm getting NULL on the entries GET request as well, instead of an empty array... any ideas?

@tuupola
Copy link
Owner

tuupola commented May 2, 2018

Not really. Try to compare to everything to how it is done with the original Todo's.

@controlnocontrol
Copy link
Author

OK I figured the issue out!

I had the ZendEntryRepository options set to ['buffer_results' => true]. I had added that thinking it might come in useful due to the bug reported in #39.

Now I wonder how to solve the issue of running consecutive queries moving forward?

@controlnocontrol
Copy link
Author

Sorry if I wasn't clear enough, but removing ['buffer_results' => true] fixed the issue.

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

No branches or pull requests

2 participants