[katello-devel] New call Justin added to AR

Hugh Brock hbrock at redhat.com
Thu Aug 16 11:50:17 UTC 2012


On Wed, Aug 15, 2012 at 07:05:16PM -0400, Partha Aji wrote:
> 
> Many may not know this, so just highlighting a new call Just Sherrill added to katello master. Its called "pluck"
> 
> Often we just need one attribute of an AR object, for example if we just need the list of ids of environments or pulp_ids of a Repository, we'd write something like this
> 
> KTEnvironment.select(:id).where(<...>).collect {|env| env.id}
> Repository.select(:id).where(<...>).collect {|r| r.pulp_id}
> 
> One common mistake here is people forget to add the "select" so you end up loading all columns even though you just need id or pulp_id
> 
> With Justin's magic method (which is in newer versions of AR. He back ported it) one can now do
> 
> KTEnvironment.where(<...>).pluck(:id)
> Repository.where(<...>).pluck(:pulp_id)
> 
> This magic method makes sure you are only selecting what you need.

When are we moving the whole shooting match to 3.2, again?

--Hugh

-- 
== Hugh Brock, hbrock at redhat.com                                   ==
== Engineering Manager, Cloud BU                                   ==
== Aeolus Project: Manage virtual infrastructure across clouds.    ==
== http://aeolusproject.org                                        ==

"I know that you believe you understand what you think I said, but I’m
not sure you realize that what you heard is not what I meant."
--Robert McCloskey




More information about the katello-devel mailing list