This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

viral-vector
viral-vector

I have a relation set up & exposed in a relation manager. I set up a "conditions" field in the relation definition. The query that pulls the relation seems to respect the "conditions" field as it aborts there is an error with the conditions. The list the renders the relations seems to ignore the conditions as all relations are returned even if they do not respect the rules set in the "definitions" field.
My relation also ignores scope definitions.

The defenition below ignores the 'conditions' field. All relations ignore the 'conditions' & 'scope' & 'order' if they are rendered through the relation manage.

'mentors' => [ 'Mentor', 'conditions' => 'linktype = \'PRIMARY\' AND contact.crole = \'mentor\'', 'table' => 'linkster', 'key' => 'surveyid', 'otherKey' => 'contactid', 'pivot' => ['linktype','impid', 'pdfl1'], 'pivotModel' => 'Models\PivotProject', ]

viral-vector
viral-vector

any help on this

viral-vector
damianlewis
damianlewis

I'm having the same issue. The relation manager ignores the scope that's setup on the relation. I have the following relation setup on a 'Category' model:

public $hasMany = [
    'lookbooks' => [ 
        'Cerimonia\Collection\Models\Lookbook',
        'scope' => 'isPublished'
    ]
];

However the relation manager returns all related lookbooks and ignores the scope.

funteapot15611
funteapot15611

Yes, I think this is a bug, I debug the code, In the cms\vendor\october\rain\src\Database\Model.php Line 668 if ($conditions = $args['conditions']) { $relation->whereRaw($conditions); } The $relation already add the $conditions. cms\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Relations\BelongsTo.php Line 85 public function getRelationCountQuery(Builder $query, Builder $parent) { if ($parent->getQuery()->from == $query->getQuery()->from) { return $this->getRelationCountQueryForSelfRelation($query, $parent); }

    $query->select(new Expression('count(*)'));

    $otherKey = $this->wrap($query->getModel()->getTable().'.'.$this->otherKey);

    return $query->where($this->getQualifiedForeignKey(), '=', new Expression($otherKey));
}

the $query only add the $otherKey, no add the conditions. $otherKey is the primary key.

You can set the the wrong select name, such as set to select: xxx_name After run, it will print the error SQL statement, you will find that the system did not use the conditions.

The 'scope' is ignored too.

Please check. Thanks.

cydrick.nonog
cydrick.nonog

Dear all,

You can use the Extender Plugin for this.

https://octobercms.com/plugin/cyd293-extenders

Thanks

1-6 of 6

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.