ruby on rails - IN clause using active record query base in order to create list of integers -
i trying replicate sql functionality using activerecord. problem relates use of ruby join method (not confused sql join). here code:
scope :stats_tips_given, lambda { |date| where("created_at >= ? , tipper_id in(?)",date, user.stats_users(date).collect(&:id).join(', ')) }
however resultant sql query has result: select "tip_events".* "tip_events" (created_at >= '2011-04-14' , tipper_id in('4, 5, 11, 17, 22, 48, 54, 65, 88, 103, 147, 151, 181, 182, 189, 195, 190, 196, 202, 226, 227, 231, 243, 245, 232, 225, 212, 217, 220, 263, 265, 273, 281, 282, 284, 286, 293, 271, 299, 300, 309, 310, 312, 318, 321, 308, 303, 297, 333, 346, 362, 368, 377, 386, 389, 392, 353, 398, 427, 420, 434, 418, 454, 456, 477, 484, 480, 453, 450, 452, 458, 497, 498, 503, 510, 511, 515, 522, 529, 537, 540, 508, 499, 524, 521, 502, 542, 546, 548, 557, 559, 571, 575, 576, 581, 587, 562, 580, 544, 567, 565, 573, 577, 597, 606, 619, 620, 640, 636, 607, 603, 600, 596, 656, 657, 668, 676, 683, 685, 662, 677, 669, 689, 678, 690, 694, 514, 206, 304, 601, 63, 495, 150, 344, 691, 490, 545, 634, 222, 288, 534, 630, 569, 323, 697, 489, 394, 568, 661, 672, 130, 381, 590, 205, 527, 474, 184, 622'))
this query fine if didn't have single quote around list of numbers. how rectify this?
you're forming string using join
. pass actual array instead:
user.stats_users(date).collect(&:id)
instead of:
user.stats_users(date).collect(&:id).join(', ')
Comments
Post a Comment