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

AR::Relation#model would be a better API than AR::Relation#klass #6606

Merged
merged 1 commit into from
Aug 21, 2012

Conversation

amatsuda
Copy link
Member

@amatsuda amatsuda commented Jun 3, 2012

model feels more natural for programmers, and this would make library authors a bit happier since it's compatible with DM::Collection
https://github.com/datamapper/dm-core/blob/9d9f739/lib/dm-core/collection.rb#L45

@parndt
Copy link
Contributor

parndt commented Jun 3, 2012

This would be nice :-)

@rafaelfranca
Copy link
Member

Agree. I would change the internals to use model instead of klass too, and make klass and alias of model. But I don't know if we can change the @klass too.

cc/ @jonleighton @tenderlove

@alexeymuranov
Copy link
Contributor

+1, i also propose in my PR #4367 to rename set_fixture_class to �set_fixture_model.

rafaelfranca added a commit that referenced this pull request Aug 21, 2012
AR::Relation#model would be a better API than AR::Relation#klass
@rafaelfranca rafaelfranca merged commit d168c1f into rails:master Aug 21, 2012
sayap added a commit to sayap/will_paginate that referenced this pull request Oct 31, 2013
`collection.first.class` will spawn a LIMIT 1 query, while `collection.empty?`
will spawn a COUNT query. The latter is not a problem since a COUNT query is
needed anyway, so redundant ones will retrieve from cache. The former, however,
can add unnecessary load to the database.

As far as I can tell, ActiveRecord::Relation has a `klass` attribute since the
beginning in 0e0866e0565bd530ee265b9298accff4185f7022, so it should work fine.
Since rails/rails#6606, the attribute is also aliased
as `model`, though this change is only available in Rails 4.x.
sayap added a commit to sayap/will_paginate that referenced this pull request Oct 31, 2013
`collection.first.class` will spawn a LIMIT 1 query, while `collection.empty?`
will spawn a COUNT query. The latter is not a problem since a COUNT query is
needed anyway, so redundant ones will retrieve from cache. The former, however,
can add unnecessary load to the database.

As far as I can tell, ActiveRecord::Relation has a `klass` attribute since the
beginning, so it should be fine. The attribute is also aliased as `model` since
rails/rails#6606, though this change is only available
in Rails 4.x.
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.

4 participants