-
Notifications
You must be signed in to change notification settings - Fork 131
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
Illegal offset type exception with Composite Keys #113
Comments
Ref #112 |
Maybe can make |
@baopham In my current situation, I have a "messages" table that has a All of my data is indexed in ElasticSearch, and my application retrieves data directly from ElasticSearch ... I'm using Elasticquent for this, which allows me to query ElasticSearch and hydrate Eloquent models from the results. The models I don't believe laravel-dynamodb should return an array when calling If we returned I recommend we stick with Eloquent support as much as possible, and introduce additional methods like |
That's a good point. Should be a quick change. For |
Can you try |
I’d recommend using Eloquent style methods, and not just pluralizing as the “s” on the end of getKeyNames is too similar to getKeyName and could cause headaches for people ... especially if they rely on type-ahead in their editor. It’s also not clear “at a glance” as it’s just a plural... getCompositeKeyNames() seems like a clearer name? Along with a getCompositeKeys() method so we aren’t directly accessing the $compositeKey property and so models can override the return for special use cases. |
Ummm, I think that's not too convincing to me. The idea of |
Hrm ... ok, I can see that reasoning. |
The latest update works, and no longer causes the "Illegal offset type" error in Elasticquent's hydration. |
I find having to switch back and forth between array and string depending whether model is composite or not is annoying. So just something that will give me a consistent return type felt more helpful. So I'm not into having the "composite key" in the function names, but am open to better names for these functions. |
I still think getKeyNames and getKeyName are too similar, but you're reasoning for not including 'composite' in the method name makes sense ... as you may or may not be working with composite keys. Unfortunately, I don't have any good ideas on better names ... best I can come up with is |
Naming is hard 😄 Agree that they look so similar... I'll keep this in mind and we can come up with something better in the future. Closing this issue for now. |
Tagged version |
When a model has a composite key,
Illegal offset type
exceptions are thrown by third-party packages that rely on Eloquent'sgetKeyName()
to return a string.For example, Elasticquent depends on
getKeyName()
to hydrate models retrieved from ElasticSearch.I recommend reverting
getKeyName()
andgetKey()
to return the value of the$primaryKey
column in the model, and re-introducing thegetCompositeKeyName()
andgetCompositeKey()
methods to allow developers to work with composite keys when they want/need to do so.The problem is that Eloquent does not support composite keys "out of the box", so a lot of third-party packages use
getKeyName()
andgetKey()
to retrieve details about the model and expect the return value to be a string forgetKeyName()
and just use it as an array index.The text was updated successfully, but these errors were encountered: