-
Notifications
You must be signed in to change notification settings - Fork 614
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
Delegating values with default for generation in database. #777
Comments
Hi @teckwan, so there isn't much new development going on as far as adding features. There have been others who have run into the issue you are describing when using models to import into to tables that have fields that use generated values. I'd be happy to consider your ideas for solving this problem. I don't know if there is a way to dynamically identify such fields or if a parameter would need to be passed to exclude certain fields. |
Thanks for the speedy response @jkowens. I'm no connaisseur of the interface between ActiveRecord and the database but I don't think the ActiveRecord API gives us this information. Off the bat a possible implementation would be: Query the database for this information at the start only when an option is given. Concretely i think it would look somewhat like this: users = [
User.new(name: "foo"),
User.new(name: "bar"),
User.new(name: "baz")
]
User.import!(users, use_defaults: [:age]) We're able to get the column default through select column_default from information_schema.columns where table_name = 'users' and column_name = 'age'; Much like how we raise when the hashes given in input do not share the same structure, we could also raise here if the specified column(s) in Would love to know what you think about this solution. |
@jkowens would be a pleasure! I'll try to come up with something in the coming days. |
@teckwan did you end up solving this? |
Hi @Amnesthesia, unfortunately no. In the end I could not find time to dedicate for implementing it. If you're interested in implementing this don't hesitate! |
@teckwan I think I did, I opened a PR you can check out |
Hello! First of all I'd like to thank the maintainers, as this gem has been very useful for me and my organisation.
I have a question about the intended functionality of the gem. As context, I have a model whose
id
is generated by a custom function in the database. When importing using instantiated objects, theid
field is added into the insert query, and hence tries to insert values withid
asNULL
. I am able to work around this by using an array of hashes to explicitly control the attributes which are included in the insert query.Do you see any constraints/is it possible to expect a feature which allows us to delegate value generation for the database? (under certain restrictions where all objects in input has to have the concerned value of the field at
nil
for example). I'd be interested in implementing something along the lines with your approval/guidance.Thanks for your time!
The text was updated successfully, but these errors were encountered: