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

Adding support for fill_existing_with on add_belongs_to #444

Merged
merged 1 commit into from
Aug 24, 2020
Merged

Conversation

jwoertink
Copy link
Member

@jwoertink jwoertink commented Aug 22, 2020

Fixes #17
Fixes #22

Let me know if this needs to do more.

Copy link
Member

@paulcsmith paulcsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks great! I think eventually what would be awesome is allowing users to pass a block to add and add_belongs_to when in an alter statement. The block would basically run with no args which would allow you to set up all the data before it actually makes the column required:

alter table_for(User) do
  add otp_code : String, fill_existing_with: ->{
    UserQuery.new.each do |user|
      SaveUser.update!(user, otp_code: generate_code_for_user(user))
    end
  }
end

So it'd add the column as allow null, then run the block, then make it required. Would be mega helpful I think! But that can be done some other time IMO

@jwoertink jwoertink merged commit 46cdd3c into master Aug 24, 2020
@jwoertink jwoertink deleted the issues/17 branch August 24, 2020 20:55
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

Successfully merging this pull request may close these issues.

Allow default for belongs_to fields Support fill_existing_with for add_belongs_to
2 participants