Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest May 27th, 2018 59 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. # sometimes datamapper's association eager loading is too eager
  2. # with 0.10.2
  3.  
  4. class A
  5.   include DataMapper::Resource
  6.   property :id, Serial
  7.  
  8.   has n, :bs, :order => :created_at.desc
  9.   has 1, :latest_b, 'B', :order => :created_at.desc
  10. end
  11.  
  12. class B
  13.   include DataMapper::Resource
  14.   property :id, Serial
  15.   property :created_at, DateTime
  16. end
  17.  
  18. @as.each do |a|
  19.   puts a.bs.first
  20. end
  21.  
  22.  
  23. #runs select <*> from bs where a_id in (<ids of each a in @as>)
  24.  
  25. #also,
  26. @as.each do |a|
  27.   puts a.latest_b
  28. end
  29. #runs select <*> from bs where a_id in (<ids of each a in @as>) order by created_at desc
  30.  
  31. #workaround
  32. @as.each do |a|
  33.   puts B.first :a => a, :order => created_at.desc
  34. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top