Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

array_column not working for relations #583

Open
CC007 opened this issue Sep 13, 2017 · 0 comments
Open

array_column not working for relations #583

CC007 opened this issue Sep 13, 2017 · 0 comments

Comments

@CC007
Copy link

CC007 commented Sep 13, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant