Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Active Record select to return nilable #2146

Closed
wants to merge 1 commit into from
Closed

Conversation

dirceu
Copy link
Contributor

@dirceu dirceu commented Jan 8, 2025

Follow-up to #2103; it turns out you can send a nilable to select.

QueryMethods#select:

> model.features.class
=> Feature::ActiveRecord_Associations_CollectionProxy
> model.features.select { nil }
=> []

Enumerable#select:

> a = T.let([1, nil, 3], T::Array[T.nilable(Integer)])
>
> T.reveal_type(a)
>
* a.select do |num|
*   num.to_c
> end
=> [1, nil, 3]

Follow-up to #2103

QueryMethods#select:

```ruby
> model.features.class
=> Feature::ActiveRecord_Associations_CollectionProxy
> model.features.select { nil }
=> []
```

Enumerable#select:

```ruby
> a = T.let([1, nil, 3], T::Array[T.nilable(Integer)])
>
> T.reveal_type(a)
>
* a.select do |num|
*   num.to_c
> end
=> [1, nil, 3]
```
@dirceu dirceu requested a review from a team as a code owner January 8, 2025 19:10
@dirceu dirceu added the bugfix label Jan 8, 2025
@jakebrady5
Copy link
Contributor

I must admit to searching too late, but I just opened a similar PR making a different change to this return value. Just linking so we can connect conversations about the two. ❤️

@paracycle
Copy link
Member

Yeah, the behaviour is not just about nilable, but more about how you can return anything from the supplied block, so I think #2147 is the better fix.

@paracycle
Copy link
Member

Closing in favour of #2147. Please reopen if you disagree.

@paracycle paracycle closed this Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants