-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[8.x] Added class and method to create cross joined sequences for factories #40542
Conversation
Should we name it |
I like the idea. And I think both names What is the expected behaviour of: new MatrixSequence(
[['a' => 1]],
[['b' => 1], ['b' => 2]],
[['c' => 1], ['a' => 2], ['c' => 3]], // Here is the second element changed.
);
// Later has a higher priority
[
['a' => 1, 'b' => 1, 'c' => 1],
['a' => 2, 'b' => 1],
['a' => 1, 'b' => 1, 'c' => 3],
['a' => 1, 'b' => 2, 'c' => 1],
['a' => 2, 'b' => 2],
['a' => 1, 'b' => 2, 'c' => 3],
];
// Earlier has a higher priority
[
['a' => 1, 'b' => 1, 'c' => 1],
['a' => 1, 'b' => 1],
['a' => 1, 'b' => 1, 'c' => 3],
['a' => 1, 'b' => 2, 'c' => 1],
['a' => 1, 'b' => 2],
['a' => 1, 'b' => 2, 'c' => 3],
]; What do you think about this alternative? new MatrixSequence([
'a' => [1],
'b' => [1, 2],
'c' => [1, 2, 3],
]);
// Results in
[
['a' => 1, 'b' => 1, 'c' => 1],
['a' => 1, 'b' => 1, 'c' => 2],
['a' => 1, 'b' => 1, 'c' => 3],
['a' => 1, 'b' => 2, 'c' => 1],
['a' => 1, 'b' => 2, 'c' => 2],
['a' => 1, 'b' => 2, 'c' => 3],
]; |
Marking as draft pending response to feedback. |
This indeed feels like a nice alternative. It prevents human error and is much easier to read/understand. However for unknown reasons and possibly lack of knowledge about defining a matrix I don't feel that convinced about its signature. Have you seen this somewhere before? I would at least rename the current class to |
Sorry @thomasowow I forgot to answer. I made my example like multiple foreach loops: foreach ([1] as $a) {
foreach ([1, 2] as $b) {
foreach ([1, 2, 3] as $c) {
Model::create([
'a' => $a,
'b' => $b,
'c' => $c,
]);
}
}
} |
Adds a new
CrossJoinSequence
class that helps cross joining multiple sequences.Usage:
Current way of achieving this:
More complex example: