-
Notifications
You must be signed in to change notification settings - Fork 109
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
Help needed with queriesOne #613
Comments
Hi! I can't immediately see a problem with the code. Are you able to share the stack trace for the error? Just wondering exactly where that is coming from. |
@lindyhopchris thanks for the quick response. I'm still experimenting with this and it looks like removing the I had this initially: return [
'rate' => [
self::SHOW_SELF => false,
self::SHOW_RELATED => false,
self::SHOW_DATA => isset($includedRelationships['rate']),
self::DATA => function () use ($resource) {
return $resource->rateQuery();
},
],
]; And now this: return [
'rate' => [
self::SHOW_SELF => false,
self::SHOW_RELATED => false,
self::SHOW_DATA => isset($includedRelationships['rate']),
],
]; I've got a few other things to try – when I'm through with them I will give you an update, because overall I don't think I understand |
I think I've figured it out. The confusion came from the fact that I can usually use the same method in both the adapter and the schema, e.g.: // Adapter
/**
* Return the BelongsTo relationship for the company.
*
* @return BelongsTo
*/
protected function company(): BelongsTo
{
return $this->belongsTo('company');
}
// Schema
return [
'rate' => [
self::SHOW_SELF => false,
self::SHOW_RELATED => false,
self::SHOW_DATA => isset($includedRelationships['company']),
self::DATA => function () use ($resource) {
return $resource->company;
},
],
]; In the above In my case the return [
'rate' => [
self::SHOW_SELF => false,
self::SHOW_RELATED => false,
self::SHOW_DATA => isset($includedRelationships['rate']),
self::DATA => function () use ($resource) {
return $resource->rateQuery()->first();
},
],
]; I think the documentation could make it clearer here that when using |
Aha, you posted the solution just as I was writing a message telling you what the bug was! Yeah, definitely could be clearer in the docs. The |
Have labelled as a docs issue to remind me to update the docs! |
Awesome! Thanks for your help |
Hi,
I'm trying to use
queriesOne
for a resource but can't seem to get it right. To cut to the chase, this is the error I'm currently getting:Now more about the setup: I've got some time entries which are periods of time recorded by workers (aka "punches"). These time entries have a worker ID as well as a task ID.
Now these workers can have different hourly rates and the applied one can differ based on the nature of the task. So I've got another table
task_workers
connecting the workers to tasks, and that table also has a rate ID.This is roughly what it looks like:
What I'm trying to achieve here, is the possibility to include the rate when querying the time entries, as a has-one relationship.
As you can see, using a regular Eloquent relationship is tricky (impossible, I think), because there is no direct link between time entries and task workers.
The query to fetch the rate from the
TimeEntry
model class is fairly straightforward, however:This is the query I'm currently trying to use with the
queriesOne
relationship. And this is the corresponding method from the time entry's adapter:I also have the following value for
$includePaths
at the top, to avoid eager loading errors:I also added
rate
to the list of authorised includes in the validators file.And I get the error mentioned at the beginning when I try querying the endpoint:
My guess is I'm using
queriesOne
in a wrong way, but I can't quite put my finger on it. Can you see what's wrong?Cheers,
Yannick
The text was updated successfully, but these errors were encountered: