Oh my God... Those cars of mine, and those are my cars...are you still arguing about this difference? Are there too few projects?
You need to have both and use both. Is there any conflict between the two? There won't be any problem if "those cars of mine" and "those are my cars" appear separately in an article, right, as long as the context is appropriate.
You are already using ORM, but you are still struggling with this issue? ORM allows you not to worry about what happens in the internal sql. Use the first method and wait until the project business is fully developed before considering optimization.
Personally, I think the second one is better.
According to active_record, it should be written in user. Because cars is an attribute of user and should be obtained from user. As for adding complex queries in the future, it cannot be expanded if placed in user? ? ?
I recommend your group to read this
There is also a third volume, but there is no Chinese version
If you write both methods, they will definitely work. I think from an understanding point of view, $user->myCars() is more complex with human thinking than $car->list($userId)
Are you using laravel? You can look at the example on the first floor. Is there really any point in arguing about this? It’s so low
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn