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

PHP Warning: Illegal offset type in isset or empty #112

Closed
foxted opened this issue Nov 29, 2017 · 10 comments
Closed

PHP Warning: Illegal offset type in isset or empty #112

foxted opened this issue Nov 29, 2017 · 10 comments

Comments

@foxted
Copy link

foxted commented Nov 29, 2017

Hi there,

First of all, thanks for working on this package, it is awesome.

However, when trying to retrieve an item with a query, I get this error:

PHP Warning:  Illegal offset type in isset or empty in /home/vagrant/Sites/Liftmap/vendor/laravel/framework/src/Illuminate/Support/Str.php on line 487

My query is the following:

$item = (new Model)->find($id);

When I try to fetch it using a where query:

$item = (new Model)->where('id', $id)->get();

I get a different error:

PHP Notice:  Array to string conversion in /home/vagrant/Sites/Liftmap/vendor/baopham/dynamodb/src/DynamoDbQueryBuilder.php on line 741

I am actively trying to find the cause of it all, but so far, only querying all the records is working. If anybody has an idea on why this could be happening, it would be much appreciated.

Thanks!

@baopham
Copy link
Owner

baopham commented Nov 29, 2017

What is your $id? Is it a string or? Can you show me your model class? What version of the library are you using?

@foxted
Copy link
Author

foxted commented Nov 29, 2017

My $id is an integer, I am using the autoincrement ID from another resource in a SQL database. Here is my class code:

<?php 

namespace App;

use BaoPham\DynamoDb\DynamoDbModel;

class Results extends Model {

    protected $table = "local_results";

    protected $fillable = ['id'];

}

I am using the latest version I think, 4.1.0.

@baopham
Copy link
Owner

baopham commented Nov 29, 2017

Thanks :)
More questions...
What is you Dynamodb table schema? What is the output of $model->getKeyNames()

I will do some troubleshooting in about 10hours...

@foxted
Copy link
Author

foxted commented Nov 29, 2017

The schema only contains id, created_at and updated_at for now.

screen shot 2017-11-28 at 5 01 43 pm

EDIT: I reverted my branch to finish up some work for now, so I had to remove the package.

@zoul0813
Copy link
Contributor

Not sure if this is related, or a separate issue ... but I'm receiving a similar "Illegal offset type" error with Elasticquent. The code worked prior to the latest updates (getKeyName() now returns an array for composite key models).

Elasticquent has the following code:

$key_name = $this->getKeyName();
$attributes = $hit['_source'];
if (isset($hit['_id'])) {
  $attributes[$key_name] = is_numeric($hit['_id']) ? intval($hit['_id']) : $hit['_id'];
}

When the model being queried has a composite key, this throws an exception ...

I believe getKeyName() should be reverted back to it's original configuration where it returned the primary key only (this is the expected result as Eloquent doesn't have support for composite keys).

Due to incompatibility with an unknown number of packages that rely on the Eloquent model's "getKeyName" method, I recommend re-introducing the getCompositeKeyName() and getCompositeKey() methods.

@baopham
Copy link
Owner

baopham commented Nov 29, 2017

That should be a separate issue. Because the model in question doesn't have composite keys.

@baopham
Copy link
Owner

baopham commented Nov 29, 2017

I believe getKeyName() should be reverted back to it's original configuration where it returned the primary key only (this is the expected result as Eloquent doesn't have support for composite keys).

hmm, that is debatable because for a composite model, the primary key consists of 2 keys:

image

So in DynamoDB context, getting the key for a composite model should return both partition and sort keys. As for your Elasticquent issue, could you create an issue for it? would be great if you explain the use case why you need the partition key only, is it just for hashing? if so, we can find way for that.

@baopham
Copy link
Owner

baopham commented Nov 29, 2017

@foxted so I tried to reproduce and could not. Here are my steps:

  1. Create a table with hash key id (of type number)
  2. Seed one item
  3. Run Model::find(1)

All is successful...

I am wondering if there's something wonky with that particular record that you are trying to find.

You mention that getting all items works. What happens if you do Model::take(1)->get()->toArray()?

Can you show me the result of the above call? and if it also fails, can you show me the result of Model::all()->toArray() - assuming that there is no sensitive data.

btw, new version is up, feel free (recommending) to update to version 4.1.1

@foxted
Copy link
Author

foxted commented Nov 30, 2017

I will try version 4.1.1 and see if it fixes the issue. Model::all()->toArray() works fine, it is only happening when using find() for some reason. I'll keep you updated.

@baopham
Copy link
Owner

baopham commented Jun 25, 2018

I'm closing this one since we haven't been able to reproduce this. Feel free re-open or create a new issue for this.

@baopham baopham closed this as completed Jun 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants