I have just started to use views. I have the following:
class ProjectData < BaseModel
alias PrimaryKeyType = Project::PrimaryKeyType # <= Without this I get the compile error
belongs_to project : Project
view :projects_data do
# ...
end
# ...
end
class Project < BaseModel
# ...
has_one data : ProjectData # <= This triggers the compile error
table :projects do
# ...
end
# ...
end
The compile error:
There was a problem expanding macro 'define_has_one_base_query'
Code in macro 'has_one'
26 | define_has_one_base_query(Project, data, ProjectData, project_id, nil)
^
Called macro defined in lib/avram/src/avram/associations/has_one.cr:80:11
80 | private macro define_has_one_base_query(class_type, assoc_name, model, foreign_key, through)
Which expanded to:
> 69 | add_preload do |records|
> 70 | ids = records.map(&.id)
> 71 | empty_results = {} of ProjectData::PrimaryKeyType => Array(ProjectData)
^--------------------------
Error: undefined constant ProjectData::PrimaryKeyType
The culprit is here:
|
empty_results = {} of {{ model }}::PrimaryKeyType => Array({{ model }}) |
It seems .has_many and .belongs_to macros calls would suffer the same error if the association is a view (regular views, at least).
Is this expected to happen? If so, should this be documented?
I have just started to use views. I have the following:
The compile error:
The culprit is here:
avram/src/avram/associations/has_one.cr
Line 210 in a620fae
It seems
.has_manyand.belongs_tomacros calls would suffer the same error if the association is a view (regular views, at least).Is this expected to happen? If so, should this be documented?