-
Notifications
You must be signed in to change notification settings - Fork 64
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
Make it easier to set default associations in a Factory #385
Comments
I'm looking into this |
Thanks for looking into this @matthewmcgarvey! |
This is basically how it works now class PostFactory < Avram::Factory
def initialize
before_save do
if operation.user_id.value.nil?
user(UserFactory.create)
end
end
end
def user(u : User)
user_id(u.id)
end
end
PostFactory.create I'd imagine this could look like class PostFactory < Avram::Factory
belongs_to user : UserFactory
end The tricky part might be if this is just a macro that ends up making an initialize, how do you handle when an initialize is defined by the user? 🤔 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Depends on #331
This will most likely require changes to https://github.com/luckyframework/avram/blob/master/src/avram/save_operation.cr so that we have access to an
ASSOCIATIONS
constant that has a list of associations and the column to use.Relevant examples:
avram/src/avram/save_operation_template.cr
Line 43 in bb57679
avram/src/avram/save_operation.cr
Lines 80 to 82 in d67dd63
We'd want to add a
add_association_attributes
or something. This will be a bit more complex so I'll try to tackle it, but if someone else wants to take a stab at it, post here and I'll try to help if you run into anythingThe text was updated successfully, but these errors were encountered: