-
-
Notifications
You must be signed in to change notification settings - Fork 137
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
Dealing with multiple-inverse associations #57
Comments
@Grantovich , how could you see this working in FactoryGuy? Could you give me an idea of what you would like to see ( even if its just a copy of what FactoryGirl does ) .. will help to get my ideas going. |
@Grantovich .. I just looked over the callbacks in FactoryGirl, and I understand what you want .. I just want to make double extra sure that I have it 100% exactly correct ( the way you want it ) before I build this. |
If you're looking to implement the whole transients/callbacks thing, this is roughly how I'd envision it working in the factory definitions: FactoryGuy.define 'location',
default:
name: 'Test Location'
FactoryGuy.define 'floorplan',
default:
location: {}
name: 'Test Floorplan'
transient:
locationInverse: null
afterMake: (model, attributes) ->
switch attributes.locationInverse
when 'currentFloorplan' then model.location.set('currentFloorplan', model)
when 'upcomingFloorplans' then model.location.get('upcomingFloorplans').addObject(model) And the usage: location = factories.make 'location'
floorplan = factories.make 'floorplan', location: location, locationInverse: 'upcomingFloorplans' The If implemented as-is, this would not be backwards compatible since FactoryGuy.define 'user',
default:
username: 'bob'
isModerator: false
isAdmin: false
traits:
admin:
isAdmin: true
moderator:
isModerator: true This would be super-not-backwards-compatible, but you could leave in the ability to define traits at the top level and just give a deprecation warning. |
(By the way, I and my team really appreciate your work on this project – I was only asking for advice on how to handle our particular situation, but you've gone far above and beyond. 👏 We are on a rather time-crunched project right now, but I hope to make some contributions to Factory Guy myself once I have more Ember experience.) |
Thanks for the proposed usage Alex, that was helpful, and thanks for the kind words :) |
Ah, okay. I was looking at a section of the README that just used top-level keys for the traits. |
Hey @Grantovich , I finally got around to finishing this feature. Check it out in version 1.0.5, and let me know if you see any bugs? |
Awesome! Thanks so much for adding this, I'll try it out and report any issues I find. |
Actually I was not quite finished when I pushed out version 1.0.4 .. I am finishing it up today, and will release new version 1.0.5 when I am done. |
ok .. I fixed that issue, and its on version 1.0.6 where afterMake will work as you expected. |
Consider the following data model:
A
Floorplan
always belongs to aLocation
, but the inverse association could be one of two different options, so we set it tonull
because Ember only allows a single inverse. Unfortunately there's no clean way to deal with this situation in Factory Guy, so we end up doing thisEm.run
workaround in every test that involves floorplans:In Factory Girl, this kind of thing is usually handled with callbacks that access transient attributes to execute some custom behavior. It would of course be a substantial effort to add these features to Factory Guy, so maybe there is an easier targeted solution.
The text was updated successfully, but these errors were encountered: