pocke / rbs_rails

Apache License 2.0
282 stars 33 forks source link

Should be optional has_one and belongs_to associations #180

Closed ksss closed 3 years ago

ksss commented 3 years ago

has_one can be nil when none associated record. And belongs_to can be nil when associated id is nil. This change will help to find nilable object in model code.

pocke commented 3 years ago

I'm wondering if RBS Rails should be aware of optional: true option of belongs_to. If belongs_to doesn't receive optional: true, RBS Rails can assume the association is not nil-able. Your change for has_one looks good.

By the way, I'm planning to make the optionality more accurate. In short, User.new and User.find should return different types, because the former's attributes are nil-able but the latter's attributes aren't.

ksss commented 3 years ago

User.new and User.find should return different types

Sounds great!

I agree with you. In this PR, I will only change has_one.

ksss commented 3 years ago

Updated.

pocke commented 3 years ago

Thanks for your update! Looks good to me :+1: