Depends on #331
class ArticleBox < Box
def initialize
post { PostBox.create }
end
# This is auto-generated by the box. Putting it here just to show rough implementation
def post
before_save do
if post_id.value.blank?
record_or_id = yield
id = if record_or_id.is_a?(Avram::Model)
record_or_id.id
else
record_or_id
end
post_id id
end
end
end
end
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:
|
add_column_attributes({{ primary_key_type }}, {{ columns }}) |
|
{% for attribute in attributes %} |
|
{% COLUMN_ATTRIBUTES << attribute %} |
|
{% end %} |
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 anything
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
ASSOCIATIONSconstant 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_attributesor 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 anything