Skip to content

Cannot Filter Array of Objects on Array of Objects #63

@bobdercole

Description

@bobdercole

Hello,

I am trying to filter an array of objects with the Native target. The objects that I am trying to filter contain an array of objects. When I try to filter the array, I get a property access exception:

Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException(code: 0): Cannot read property "name" from an array. Maybe you intended to write the property path as "[name]" instead.

Here is a simplified snippet of my objects:

class Label
{
	public $name = 'something';
}

class User
{
	public $labels;

	public function __construct()
	{
		$this->labels = [
			new Label(),
			new Label(),
			new Label()
		];
	}
}

Here is a snippet of my RulerZ specification:

class UserLabelsNameSpecification implements Specification
{
	public function getRule()
	{
		return 'labels.name = "something"';
	}
}

Here is the filter:

$users = [
	new User(),
	new User(),
	new User()
];

$filtered_users = $rulerz->filterSpec($users, new UserLabelsNameSpecification());

Is RulerZ supposed to support this? Perhaps I'm doing something wrong? I could not find an example of this situation. My example works fine with the DoctrineOrm target.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions