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

Test-Eloquent-Relationship #286

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

WorldUma
Copy link

Completed Test for Eloquent Relationship. But took more than 2 hours to complete
Have doubt below task

In the route /users/{user}, the table should load the comments that are written on the task that belong to a user. Define the relationship from User to Comment in the User model, so that the Blade file users/show.blade.php would work.

Test method test_show_users_comments().

got error like
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'tasks.user_id' in 'field list' (Connection: mysql, SQL: select comments.*, tasks.user_id as laravel_through_key from comments inner join tasks on tasks.id = comments.task_id where tasks.user_id in (1))

Please can you help me
Thanks

@WorldUma
Copy link
Author

Got solutions from others
but still have an doubt Task for two-level relationship in the User model

database schema does not follow Laravel's default conventions.

User Model priously define relationship like this
public function comments() { return $this->hasManyThrough(Comment::class, Task::class); }

in this case laravel doesnt accept default convention ah? @PovilasKorop
Thanks

@WorldUma
Copy link
Author

Hi, @PovilasKorop
Can you pls approve

Thanks

@PovilasKorop
Copy link
Collaborator

@WorldUma approved, seems to be passed now!

@WorldUma
Copy link
Author

@PovilasKorop Thanks

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

Successfully merging this pull request may close these issues.

2 participants