-
Notifications
You must be signed in to change notification settings - Fork 10.7k
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
[Proposal] Belongs to through #3052
Comments
Can't you use the same relationship both ways? HasManyThrough is effectively a m:m relationship, after all. |
You would just use the same relationship both ways. |
Unless I'm missing something entirely obvious, which is quite possible, I don't think it is possible to use the SchemaTable 1: ProblemTable 3 can have a |
I'd like to see a belongsToThrough relationship for models that work like the following entry -> daily -> weekly entry
daily
so if I want to find the week that entry belongs to, I can do a belongsToThrough using daily as the intermediate table. |
Would also like this relationship. The relationship as it currently stands can't necessarily be used both ways. My schema I can use a hasManyThrough on table_a to get to table_c Strictly speaking, in my case from table_c to get to table_a I want a belongsToThrough relationship.. |
How about this schema:
How is the best way to retrieve permissions for one user? |
I also can't see how
In this case,
With Laravel 4.1, we can now use
What we can't do is the inverse:
likely because Am I missing something? Or is this intended behavior? ###Edit: |
See this StackOverflow answer providing a workaround: The only issue with this is that eager-loading using this method doesn't work: $item = Item::with('store')->first();
dd($item->store); // => null |
+1 for BelongsToThrough |
@taylorotwell Maybe you should reconsider it again... |
@taylorotwell As @szainmehdi said earlier, belongsToThrough wouldn't be quite the same as HasManyThrough, because HasManyThrough is a m:m relationship and returns a collection, but what we need in belongsToThrough is to return a single object, not many. Consider the following example. Supposing we have a users table... For each user we store the city (via a city_id field), but NOT a country. The country is stored in the cities table. We could of course define a "country_id" (in addition to city_id) as well in Users table, but that would break the DRY principle. It's clear that each City has one and only one country. So a HasManyThrough relationship would be useless. class User extends Eloquent {
} |
Yep, I definitely hope you'll reconsider this proposal, @taylorotwell. It has concrete use-case scenarios and I've found myself needing this relationship twice now in my own projects. |
Would be awesome if you could implement this. I just started with Laravel but already in need of this =) Currently using this to emulate the belongsToThrough (in User model to lookup connected church) User m--1 Address m--1 Church
|
+1 for |
+1 for belongsToThrough |
Discussion can continue on #6161. |
The inverse of the hasManyThrough() relationship.
Anyone else find it useful but me?
The text was updated successfully, but these errors were encountered: