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

none query method #4609

Closed
wants to merge 1 commit into from
Closed

none query method #4609

wants to merge 1 commit into from

Conversation

xuanxu
Copy link
Contributor

@xuanxu xuanxu commented Jan 23, 2012

Here is a none method to return an empty relation from a AR model (i.e Post.none), as previously discussed here: #4548

It prevents the query hitting the database, is chainable and makes any subsequent relation empty, so Post.none.where(:author_id => 1) is also empty.

@Empact
Copy link
Contributor

Empact commented Jan 23, 2012

You might want to just update the code in the original pull request, to keep the conversation together there.

BTW I'm +1 on this idea. .where('1 = 0') is a lame hack.

@tenderlove
Copy link
Member

I'm OK with this, but I'd like more opinions. @jonleighton ?

@jonleighton
Copy link
Member

I'm okay with this too, but I think it would be better if:

  • The rationale was explained in the documentation (also explained in terms of the 'null object pattern' as that's what this is)
  • There was a CHANGELOG entry
  • Ideally I'd prefer if we used polymorphism. I.e. if Relation#none returned an instance of a NullRelation that implemented this behaviour, rather than having to have a @none_value var and special code in exec_queries.

Thanks.

@tenderlove
Copy link
Member

I agree with @jonleighton. @xuanxu can you make those changes, and we'll merge it in. Thanks for the contribution! :-)

@xuanxu
Copy link
Contributor Author

xuanxu commented Jan 24, 2012

OK, I will try to make those changes

@xuanxu
Copy link
Contributor Author

xuanxu commented Jan 30, 2012

@tenderlove Done!: #4768
¿should I backport it to 3.2?

@tenderlove
Copy link
Member

@jonleighton can you review?

@xuanxu no, we will not backport this (as it is a new feature).

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

Successfully merging this pull request may close these issues.

None yet

4 participants