Closed adamwathan closed 9 years ago
@devinfd Here for your review!
This is perfect! All my tests are passing after updating them to use the new syntax. Using the column name as the prefix feels a bit weird but given the multiple relationships using the same factory
issue it completely make sense. I'm sure there are some tweaks that may need to be made but so far this is working beautifully.
+1 Well done!
Looks awesome, Adam! Thanks so much.
All tests are green, so I'll likely merge this later today. :)
@JeffreyWay Any chance of pulling this in?
This PR adds support for overriding relationship attributes.
TL;DR
Given the following factories:
...you can override a
Post
title using the following syntax:The column name was chosen as the attribute prefix to allow separately overriding relationships that use the same factory, as it's the only reliable unique identifier for the relationship. See below for an example.
More fun
Nested relationships
This PR supports relationships of arbitrary nesting level. Given these factories:
...you can override nested relationship attributes like so:
Multiple relationships using the same factory
If you have an object that has two relationships to the same type of model but under different keys, you can still override their attributes separately.
Consider these factories:
Since I've opted to use the column name as the identifier for the relationship, you can easily override those attributes separately like so:
I needed to add the
filterArrayKeys
helper because PHP < 5.6 doesn't allow filtering an array by key and it's an annoying enough operation that duplicating it would be unfortunate. It would be nice to just create anarray_filter_keys
function and autoload it in some sort of helpers file because it definitely feels out of place in theBuilder
class, but I didn't want to make that decision alone.