Giter Site home page Giter Site logo

eloquence-base's Introduction

eloquence-base's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

eloquence-base's Issues

Does not work with staudenmeir/belongs-to-through

BelongsToThrough isn't included in Laravel core, so we have to use this third party package. The roblem is that it doesn't work with eloquence searchable. The SQL query that is constructed is missing a column name and value it has to match with.

Compliance with PSR-4 autoloading

With Composer 2 being released, this project will need to comply with PSR-4.
It's not entirely clear to me what part does not comply, but composer complains about src/Contracts/Searchable/Searchable.php.

error

can you help me whit this error
image

Possible bug with `morphedByMany` relations

It appears that I cant search properly in my morphedByMany relations.

I've tracked it down to

$join->where($relation->getMorphType(), '=', $parent->getMorphClass());

 if ($relation instanceof MorphOneOrMany) {
            $join->where($relation->getQualifiedMorphType(), '=', $parent->getMorphClass());
        } elseif ($relation instanceof MorphToMany || $relation instanceof MorphByMany) {
            $join->where($relation->getMorphType(), '=', $parent->getMorphClass());
        }

The last $parent->getMorphClass() should be $relation->getMorphClass(), in particular when the relation is a morphedByMany. So this elseif statement needs to be split.

I dont have a good testcase but here's the main setup that causes the bug:

table: "assets"
columns: id, name

table: "asset_relations"
columns: asset_id, morphable_id, morphable_type

table: "user"
columns: id, username
// App\Models\Asset.php (Eloquent model)

protected $searchableColumns = ['users.username'];

 public function users()
    {
        return $this->morphedByMany(User::class, 'morphable', 'asset_relations');
    }
// App\Models\User.php (Eloquent model)

public function assets()
{
    return $this->morphToMany(Asset::class, 'morphable', 'asset_relations');
}

Lastly, try to make a query like this:
Asset::with(['user'])->search('somename')->get();

The SQL itself will generate the wrong query since asset_relations will be joined on morphable_type = App\Models\Asset instead of the correct App\Models\User.

Aggregate is failing with certain db settings

In the current Query Builder instance in this package, the aggregate method doesn't remove things like order at least like the latest laravel version does to remove errors around full group by.

I can run the same query twice using this package enabled and without and the resulting queries look like:

With:

select count(*) as aggregate from "manufacturers" order by "id" desc

Without:

SELECT count(*) as aggregate FROM "manufacturers"

This causes the query to fail on servers where this option is enabled, whereas base installs of laravel, can function properly with this option.

For reference, https://github.com/laravel/framework/blob/master/src/Illuminate/Database/Query/Builder.php#L2421

Is this package still maintained?

This is great package, really good and I like it (particularly Searchable), but is it still maintained?

I am asking because I plan to use this package on a project I'm currently working on (Laravel 5.6), but later I plan to upgrade to newer versions of Laravel:

  • to 5.7, then to 5.8 (when it's released) and finally to 5.9 (which should be LTS if I'm not wrong)

... but I'm worried because if this package is not maintained - there may be issues when upgrading (for example, it will not work on 5.9, or some other issues may occur in the meantime... :) ).

Latest commit was on 10 Mar, and I see some issues are still opened (without any replies/answers from maintainer(s), both on /eloquence-base & /eloquence).

Search Tweak

How hard would it be to add the function in where it give higher weights to searches that contain words combined together. Basically from the example package:

Prioritize matches containing "John Doe" above matches containing only "John" or "Doe".

where subquery bug

  • Laravel Version: 7.28.3
  • PHP Version: 7.3.14
  • Database Driver & Version: MySQL 5.7.22

Description:

After upgrade from L6 to L7 some queries begun to fail

Steps To Reproduce:

code:

                 ActionLog:: /*...*/
                 ->where(function ($query) {
                     $query
                         ->where('action', 'ended')
                         ->orWhere('action', 'failed');
                 })->get();

result:

SQLSTATE[HY000]: General error: 1096 No tables used (SQL: select exists(select * from `action_logs` where `user_id` = 903db834-1484-4461-abec-23b17645ec2c and `id` > 17 and (select * where `action` = ended or `action` = failed) is null order by `id` desc) as `exists`)

work around:

ActionLog:: /*...*/
->whereRaw("(action = 'ended' OR action = 'failed')")->get();

//--------------
code:

                 ActionLog:: /*...*/
                 ->where(function ($q) {
                     $q
                         ->where('description', 'like', '%Wizard ended')
                         ->orWhere('description', 'like', '%Wizard failed');
                 })->get();

result:

SQLSTATE[HY000]: General error: 1096 No tables used (SQL: select count(*) as aggregate from `action_logs` where (select * where `description` like %Wizard ended or `description` like %Wizard failed) is null)

work around:

ActionLog:: /*...*/
->whereRaw("(description like '%Wizard ended' OR description like '%Wizard failed')")->get();

Eloquent call without removing any lines.

first one:

ActionLog::where('user_id', $this->userId)
                ->where('id', '>', $start->id)
                ->whereRaw("(action = 'ended' OR action = 'failed')")
                // TODO: review this after upgrade laravel builder
                // ActionLog::->where(function ($query) {
                //     $query
                //         ->where('action', 'ended')
                //         ->orWhere('action', 'failed');
                // })
                ->latest('id')
                ->exists();

second one:

    public function index(IndexRequest $request)
    {
        $userId = request('user_id');
        $logId = request('log_id');

        $log = ActionLog::select(
            'id',
            'user_id',
            'action',
            'created_at',
            'description'
        )
            ->search(request('search'))
            ->when($userId, function ($q, $userId) {
                // Wizard logs by users
                $q->where('user_id', $userId);
            })
            ->when($userId && !$logId, function ($q) {
                $q->whereRaw(
                    "(description like '%Wizard ended' OR description like '%Wizard failed')"
                );
                // TODO: review this after upgrade laravel builder
                // $q->where(function ($q) {
                //     $q
                //         ->where('description', 'like', '%Wizard ended')
                //         ->orWhere('description', 'like', '%Wizard failed');
                // });
            })
            ->when($logId, function ($q, $logId) {
                $start = ActionLog::select('id')
                    ->where('id', '<=', $logId)
                    ->where('description', 'like', '%Wizard started')
                    ->orderBy('id', 'desc')
                    ->first();

                if ($start) {
                    // Wizard logs details by users by log id
                    $q->whereBetween('id', [$start->id, $logId]);
                } else {
                    $q->where('id', $logId);
                }
            })
            ->orderBy(request('order_by', 'id'), request('order', 'asc'))
            ->paginate(request('paginate', 15));

        return ActionLogResource::collection($log);
    }

NOTE: after removing elquence trait the queries work properly

Searchable requires disabling the 'strict' mode (or disabling just 'ONLY_FULL_GROUP_BY')

Searchable doesn't work in 'strict' mode (which is enabled by default in the newer versions of Laravel).
In config/database.php this is required:

strict' => false,

or this:

            'strict' => true,
            // Explicitly enable specific modes, overriding strict setting
            'modes' => [
                // 'ONLY_FULL_GROUP_BY',
                'STRICT_TRANS_TABLES',
                'NO_ZERO_IN_DATE',
                'NO_ZERO_DATE',
                'ERROR_FOR_DIVISION_BY_ZERO',
                'NO_AUTO_CREATE_USER',
                'NO_ENGINE_SUBSTITUTION'
            ],

to make Searchable working...
It would be nice to mention this in the documentation ;)

Eloquence builder breaks parameter grouping

Laravel 7.29.3

Sofa\Eloquence\Builder

>>> App\Models\User::where('name', '=', 'John')->where(function ($query) { $query->where('votes', '>', 100) ->orWhere('title', '=', 'Admin'); })->toSql();
=> "select * from `users` where `name` = ? and (select * where `votes` > ? or `title` = ?) is null"

Illuminate\Database\Eloquent\Builder

>>> App\Models\User::where('name', '=', 'John')->where(function ($query) { $query->where('votes', '>', 100) ->orWhere('title', '=', 'Admin'); })->toSql();
=> "select * from `users` where `name` = ? and (`votes` > ? or `title` = ?)"

As you can see, when Eloquence is used, it starts a subquery instead of a parameter group.

Error with search and pagination when using group by

Recent change introduced in Laravel 7.10.0, and merged from laravel/framework#32624 broke search and pagination functionality when Eloquence is used with group by queries.

Problem with both is that base version of runPaginationCountQuery is changed, and now uses subquery to get count for pagination. This produces multiple rows of aggregates, and the pagination total is returned from first row only.

This can be solved by replacing/removing the method in Sofa\Eloquence\Query\Builder, but then search query gets wrapped in subquery and times out for me, so I couldn't get any further in investigating it.

Running unit tests that involve Eloquence models fail

In app level unit tests that involve models that are using Eloquence, if the test isn't updated to use a stub like the unit tests of this package, then the tests will fail if there are enough unit tests that affect the model.

For example just running unit tests that would touch something eloquence wise (in my case Mappable and Mutable), outside of running individual tests which pass, will fail.

Here is output of a test which ends up trigger this error when run in my test suite but not in an individual test. And no that's not a copy paste error, that is directly from the run, and note that this is the second test to fail, but is 65th out of 90 in my test suite

2) Tests\Unit\Observers\ProductObserverTest::testPriceChangesAreStored
Error: Maximum function nesting level of '256' reached, aborting!

/var/www/html/project1/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1367
/var/www/html/project1/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php:914
/var/www/html/project1/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php:518
/var/www/html/project1/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php:901
/var/www/html/project1/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php:929
/var/www/html/project1/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php:623
/var/www/html/project1/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php:571
/var/www/html/project1/vendor/sofa/hookable/src/Hookable.php:111
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/eloquence-mutable/src/Mutable/Hooks.php:43
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:84
/var/www/html/project1/vendor/sofa/hookable/src/Pipeline.php:88
/var/www/html/project1/vendor/sofa/hookable/src/Hookable.php:247
/var/www/html/project1/vendor/sofa/hookable/src/Hookable.php:114
/var/www/html/project1/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1531
/var/www/html/project1/tests/Unit/Observers/ProductObserverTest.php:128
/home/dcox/.config/composer/vendor/phpunit/phpunit/src/TextUI/Command.php:203
/home/dcox/.config/composer/vendor/phpunit/phpunit/src/TextUI/Command.php:159

Individual Run:

phpunit --filter testPriceChangesAreStored
PHPUnit 8.0.4 by Sebastian Bergmann and contributors.

.                                                                   1 / 1 (100%)

Time: 340 ms, Memory: 26.00 MB

OK (1 test, 12 assertions)

Other tests I was able to swap the usage to a EloquentStub like your unit tests, but that's just not always applicable to fix things.

The Observer test here is testing that changes in a new system make their way into a legacy system, where the models receiving the new system changes are utilizing Eloquence, Mutable, and Mappable as the field names are....less than ideal, and the legacy system has Y/N booleans that Mutable handles. It is worth noting that any amount of testing seems to trigger this issue once you are testing the same App level model over even a few tests in the same run.

Add to readme that "withCount" is not supported

I had to browse through the github issues to find out that withCount is not supported in combination with ->search().

Consider the following example:

User::where('operator_id', 5)->withCount(['timeRegistrations AS time_sum' => function ($query) {
    $query->select(DB::raw("SUM(time_spent) as time_sum"));
}])->search('%something%')->paginate();

What seems to happen is that the query seems to resolve to WHERE 'operator_id' = '%%something%%' which is the parameter that was passed to the search function.

I doubt if this can be fixed easily. However it would be nice if this was in the readme so people know what to avoid.

Call to undefined method Sofa\Eloquence\Query\Builder::orWhereHas()

Laravel 8.19.0
PHP 7.4.2
MySQL 5.7.26

I get an error when using a where subquery:

Ticket::where(function($query) {
            $query->whereHas('timeRegistrations', function ($query) {
                $query->whereNull('invoice_id');
            })->orWhereHas('usedProducts', function ($query) {
                $query->whereNull('invoice_id');
           });
})->get();

Results in Call to undefined method Sofa\Eloquence\Query\Builder::orWhereHas()

Without the subquery, the orWhereHas method works. Seems it is using the wrong Builder class within the subfunction, but I don't know where to start to investigate this.

Possibly related to #31.

Many-to-many polymorphic relation not joining correctly

The joiner won't complete many-to-many polymorphic relation joins on both the join id and the join type. Models with relationships like those in Eloquent documentation:

public function tags()
{
   return $this->morphToMany('App\Tag', 'taggable');
}

result in partial joins like:

select * from "users" 
  inner join "profiles" on "users"."profile_id" = "profiles"."id" 
  inner join "taggables" on "taggables"."taggable_id" = "profiles"."id" 
  inner join "tags" on "taggables"."joiner_tag_stub_id" = "tags"."id"'

Join SQL is missing second type option:

... and "taggable_type" = ?

This would be similar to the morphOne option that exists today:

select * from "users" 
  inner join "profiles" on "users"."profile_id" = "profiles"."id" 
  inner join "companies" on "companies"."morphable_id" = "profiles"."id" and "companies"."morphable_type" = ?

Bug in calling unexisting function

https://github.com/jarektkaczyk/eloquence-base/blob/master/src/Relations/Joiner.php#L197

This function getQualifiedForeignKey doesnt exist anymore on BelongsTo, see:

https://github.com/laravel/framework/blob/5.8/src/Illuminate/Database/Eloquent/Relations/BelongsTo.php

It is now named getQualifiedForeignKeyName. I tried to trace down the date+version at which it was changed, but for some reason I am unable to find it in the commits. If anyone want to take a look that would be appreciated:

https://github.com/laravel/framework/commits/5.8/src/Illuminate/Database/Eloquent/Relations/BelongsTo.php

As for a quickfix: anyone know how to easily override this class function so that I can make it work on Laravel 5.7/5.8?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.