On Jun 15, 2014, at 9:45 AM, Hassan Schroeder wrote: > On Sun, Jun 15, 2014 at 1:29 AM, Ronald Fischer <[email protected]> wrote: > >> Card.where(box_id: params[:box_id]).map {|c| c.id }.each do |cid| >> # .... Do something with cid >> end > >> This is compact, but I don't like the fact that first, all data from the >> retrieved Card objects needs to be stored in memory at least temporarily >> (there is even a 'text' field in Card!), but only the id is needed. > >> I wonder whether there is a simpler solution, using just >> ActiveRecord functions. > > As Colin pointed out, > > (assume that ) box = Box.find(box_id) > > box.cards # has the cards you want *if* you need all the attributes > > box.cards.pluck(:id) # builds a query to fetch *only* the card ids > > HTH, > -- > Hassan Schroeder ------------------------ [email protected] > http://about.me/hassanschroeder > twitter: @hassan
What about box.card_ids ? Doesn't that do much the same thing? Walter > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/rubyonrails-talk/CACmC4yD_VCpXyTubObFfi5u0pLNV7-97gU8KVeEBF5HxgBZMWQ%40mail.gmail.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/03726039-3549-42BB-94F6-BF124843149D%40wdstudio.com. For more options, visit https://groups.google.com/d/optout.

