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

Add an activerecord relation blacklisted array method #17128

Closed
wants to merge 1 commit into from
Closed

Add an activerecord relation blacklisted array method #17128

wants to merge 1 commit into from

Conversation

regonn
Copy link

@regonn regonn commented Oct 1, 2014

:[]= is destructive method.
And this is not used in ActiveRecord::Relation.
It's a nonsense.

@rafaelfranca
Copy link
Member

I believe this method is delegted to the array right? If so I believe it make sense. Which kind of problems it can bring?

@regonn
Copy link
Author

regonn commented Oct 1, 2014

:[]= method can permute array elemets. It likes destructive method.

like :delete_at

> animals = ["mouse", "cow", "tiger", "rabbit", "dragon"]
=> ["mouse", "cow", "tiger", "rabbit", "dragon"]
> animals[3, 2] = 'dragon'
=> "dragon"
> animals
=> ["mouse", "cow", "tiger", "dragon"]

So I think this blacklist needs to include :[]=.

@rafaelfranca
Copy link
Member

delete_at and friends are blacklisted because they give the wrong impression that the change will be reflected in the database. I don't see any problem with []=.

@regonn
Copy link
Author

regonn commented Oct 2, 2014

I see.

I think I don't see any problem with :compact too. But it is included in blacklist.

So we need to choose

  • remove :compact from blacklist

or

  • add :[]= to blacklist

@sgrif
Copy link
Contributor

sgrif commented Nov 23, 2015

Since Relation includes Enumerable now, I've opted for 9d79334 instead.

@sgrif sgrif closed this Nov 23, 2015
sgrif added a commit that referenced this pull request Nov 23, 2015
As was pointed out by #17128, our blacklist of mutation methods was
non-exhaustive (and would need to be kept up to date with each new
version of Ruby). Now that `Relation` includes `Enumerable`, the number
of methods that we actually need to delegate are pretty small. As such,
we can change to explicitly delegating the few non-mutation related
methods that `Array` has which aren't on `Enumerable`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants