Replies: 2 comments 2 replies
-
The class_table_inheritance plugin skips updates of child tables if there are no columns to save. I assume this is a validation issue and not a saving issue. A before_validation hook to populate missing columns from child tables not originally queried could work (as you mentioned in option 2). A basic approach could be something like: missing_columns = columns - @values.keys
unless missing_columns.empty?
if row = this.select(*missing_columns).single_record!
@values = row.merge!(@values)
end
end Performance-wise, such an approach would definitely be preferably to an after_initialization approach. |
Beta Was this translation helpful? Give feedback.
-
This would happen with any validation operating on the missing columns, it's not specific to |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
When the model object is queried from the top-level parent in a CTI relationship, the model object isn't complete and is missing attributes from the child's table.
This is usually fine, but one issue I've ran into is that validations fail the first time, but will potentially succeed the second time when you're debugging, depending on what actions you take. This can be incredibly confusing.
ie.
This is covered a little bit inside the CTI documentation - you need to call
refresh
on the instance to fill in the gaps between the parent and child tables. Only downside is you need to remember to do this.What I'd like to do is eliminate this sharp edge. I tried this naive solution, which works but seems incredibly wasteful:
I'm looking for either:
Suggestions on improving this naieve implementation.
Improvements for the workflow around saving. Is this a bug? Should Sequel backfill before saving? I'm not sure this is even possible but maybe it can be paired with dirty tracking somehow.
Beta Was this translation helpful? Give feedback.
All reactions