Skip to content

array_column not working for relations #583

Open
@CC007

Description

@CC007

Say I have 2 tables:

bars

+--+---+
|id|bar|
+--+---+

foos

+--+------+---+
|id|bar_id|foo|
+--+------+---+

And in php you have the active record model classes foo and bar.

If you have a belongs_to relation from foo to bar, you can use $foo_var->bar

The problem is that if you have an array of foo objects ($foo_arr), then you are not able to use

array_column($foo_arr, 'bar') to get an array of bar objects.

Workaround:

$bar_arr = array_map(
    function($foo) {
        return $foo->bar;
    },
    $foo_arr
);

Request to fix this issue by making array_column work with php activerecord relations or to provide a function that has the same functionality.

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