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

Next version input #21

Closed
dariusj18 opened this issue Aug 27, 2018 · 4 comments
Closed

Next version input #21

dariusj18 opened this issue Aug 27, 2018 · 4 comments

Comments

@dariusj18
Copy link

I have been working on similar things as you for this package over the last several months.

https://github.com/dariusj18/laravel-eloquent-join/commits/master

I would like to present some differences in where you have gone vs where I did.

  1. I tried to do more Laravelish way of using method names to change what type of Join to use. Doing this allows for cross joins as well (I don't use them much, but Laravel has specific cross join methods as well). However there is definitely the issue of reverse compatibility.
  2. I added the BelongsToManyJoin relation, I may have been naive, however it worked for my purposes.
  3. I added orderByJoinPivot, this is a natural extension of the BelongsToManyJoin and is very useful.
  4. I see you also removed the groupBy, however I don't think there should be the extra select added automatically either. If anything, I think it would be best to have an additional method to let the user choose to add the grouping if they think it is needed.
  5. I switch the ExtendRelationsTrait to override the newBelongsTo and newHasOne methods that Laravel added in 5.5 [5.5] Allow developers to extend Relationship Classes laravel/framework#22617

I would appreciate any feedback on my suggestions.

@fico7489
Copy link
Owner

1.yes 3.* is not backward compatible, because of this I named it 3.* not 2.*
I don't want to supports < 5.5 anymore
By my opinion I think that is better to pass join type in parameter rather that use 3 different methods

2.I have in plan also to support HasMany relation, method for join should be something like this

public function orderByJoin($column, $sortBy = 'asc|desc', $joinType = 'left|inner|cross', $sortTypeJoin = 'id', $sortByJoin = 'asc')

3.orderByJoinPivot can be usefull also, but this method is for pivot table on HasMany relation

4.group by is not needed anymore because I added this https://github.com/fico7489/laravel-eloquent-join/blob/master/src/EloquentJoinBuilder.php#L101
maybe I can allow user from choose between this new way or group by

5.Extending laravel relations are awkward, acctually I requested that improvement :

laravel/framework#22382

😄

@dariusj18
Copy link
Author

  1. Yeah, I prefer it that way too, but using the method name is more Laravely.

  2. The issue I see with either method is it's kind of an unexpected behavior. It also doesn't give you the option to determine which records to get, with your subquery there is no ordering, so there is nothing giving the user the ability to determine which is the top record, it leaves that up to the database and how it decides to store records. This is at it's root is an issue with Eloquent and how it assumes one row per record when hydrating models

  3. Excellent, makes sense.

@fico7489
Copy link
Owner

fico7489 commented Aug 27, 2018

2.hm yeah I really didn't finished concept but it will be roughly something like this :

order by related table

//order products by units name (subquery will get first unit asc by name)
Products::orderByJoin('units.name', 'asc', 'left', 'name', 'asc')

//order products by units name (subquery will get last unit asc by name)
Products::orderByJoin('units.name', 'asc', 'left', 'name', 'desc')

//order products by units name (subquery will get first unit asc by id)
Products::orderByJoin('units.name', 'asc', 'left', 'id', 'desc')

//order products by units name (subquery will get first unit asc by min id)
Products::orderByJoin('units.name', 'asc', 'left', 'value', 'id', 'min')

order by pivot table

Products::orderByJoinPivot('units.value', 'asc', 'left', 'value', 'asc', 'min')
Products::orderByJoinPivot('units.value', 'asc', 'left', 'value', 'asc', 'max')

tables

products
id|name|shop_id

units
id|name

product_unit
id|product_id|unit_id|value

@fico7489
Copy link
Owner

fico7489 commented Sep 3, 2018

If you have more questions or suggestion feel free to ask me

@fico7489 fico7489 closed this as completed Sep 3, 2018
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

No branches or pull requests

2 participants