You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed the returns signature of any belongs_to association on a model is always nilable in the RBI file, even if the belongs_to is not optional. Rails will raise an error if a nil value is present for such an association. I don't find it optimal to add T.must everywhere to change this in application code.
I changed Tapioca::Dsl::Compilers::ActiveRecordAssociations#populate_single_assoc_getter_setter and it seems to work:
association_type = if !reflection.options[:optional] && reflection.is_a?(ActiveRecord::Reflection::BelongsToReflection)
association_class
else
as_nilable_type(association_class)
end
What do you think ?
The text was updated successfully, but these errors were encountered:
thierry-tranchant
changed the title
RBI: getter methods on belongs_to associations have returns(T.nil(...)) as sig but belongs_to reflection is not optional
RBI: getter methods on belongs_to associations have returns(T.nilable(...)) as sig but belongs_to reflection is not optional
Sep 6, 2024
I noticed the
returns
signature of anybelongs_to
association on a model is alwaysnilable
in the RBI file, even if thebelongs_to
is notoptional
. Rails will raise an error if anil
value is present for such an association. I don't find it optimal to addT.must
everywhere to change this in application code.I changed
Tapioca::Dsl::Compilers::ActiveRecordAssociations#populate_single_assoc_getter_setter
and it seems to work:What do you think ?
The text was updated successfully, but these errors were encountered: