Remove invalid query example from ActiveRecord changelog. #8457

Closed
wants to merge 2 commits into from

3 participants

@caike

These queries don't seem to work without explicitly informing
the join table, like:

Post.where(comments: { name: 'foo' }).joins(:comments)

Which also reflects what tests in test/cases/relation/where_test.rb
currently look like.

@caike caike Remove invalid query example.
These queries don't seem to work without explicitly informing
the join table, like:

  Post.where(comments: { name: 'foo' }).joins(:comments)

Which also reflects what tests in test/cases/relation/where_test.rb
currently look like.
2310d62
@carlosantoniodasilva
Ruby on Rails member

Perhaps we should show the full examples instead, using includes, which is what apparently it is supposed to show?

Post.includes(:comments).where(comments: { name: 'foo' })
Post.includes(:comments).where('comments.name' => 'foo')
Post.includes(:comments).order('comments.name')

Wdyt? Thanks!

@rafaelfranca
Ruby on Rails member

The text says that that references are not needed" Note that you do not need to explicitly specify references in the following cases, as they can be automatically inferred:"

Need to research if that behavior changed intentionally or due some bug.

@caike

@rafaelfranca Yeah, that text was confusing. I looked for something like that on the tests and all I could find were assertions with joins. I couldn't find any assertion stating that the join would be inferred.

As for showing a full (and perhaps correct) example, I think it's already shown right above the line that was removed:

Post.includes(:comments)
    .where("comments.name = 'foo'")
    .references(:comments)

@carlosantoniodasilva Isn't the code you posted, using 'comments.name' => 'foo', exactly what we are supposed to avoid from now ?

@caike

@carlosantoniodasilva nevermind, got it.

@rafaelfranca
Ruby on Rails member

:shipit:

@rafaelfranca
Ruby on Rails member

@caike you are right. Thanks

@carlosantoniodasilva
Ruby on Rails member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment