Skip to content

Delimiter not working when filtering id through a wherehas filter. #121

@stefan-beech

Description

@stefan-beech

I'm the creator of issue #119.
And I have come further in my journey to get the functionality I want, expect I am running into a problem.
The problem being that a delimiter on a WhereIdIn isn't called when the filter is passed through a WhereHas filter.
Example url http://localhost/api/v1/companies?filter[sectors][id]=2,3 returns
Expecting filter value to be an array, or a string when a string delimiter is set.
When looking further into the code I have noticed the delimiter function isn't even called and the apply will call the deserialize and down the line toArray gets called before the delimiter is even set and will always result in this error.

SectorSchema filters

/**
     * Get the resource filters.
     *
     * @return array
     */
    public function filters(): array
    {
        return [
            WhereIdIn::make($this)->delimiter(','),
            FilterOnNullWhenZero::make('parent', 'parent_id')
        ];
    }

CompanySchema filters.

    /**
     * Get the resource filters.
     *
     * @return array
     */
    public function filters(): array
    {
        return [
            WhereIdIn::make($this)->delimiter(','),
            Where::make('company_type'),
            Where::make('name'),
            WhereHas::make($this, 'sectors'),
            CompanyFilter::make('searchTerm'),
        ];
    }
    

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions