Hi,

ich übergebe meiner find Methode ein großes Array von IDs, deren
zugehörige Datensätze aus der DB geladen werden sollen. Die IDs sind
nicht zwingend zusammenhängend, weshalb eine Abfrage mit LIMIT oder
OFFSET ausscheidet.

Beispiel:
ids = [41,42,51,52,61,62]
MapCell.find(ids)

funktioniert! Schaut man sich die Logfiles an, dann sieht man:
  MapCell Load (0.8ms)   SELECT * FROM `map_cells` WHERE
(`map_cells`.`id` = 41)
  MapCell Load (0.3ms)   SELECT * FROM `map_cells` WHERE
(`map_cells`.`id` = 42)
  MapCell Load (0.3ms)   SELECT * FROM `map_cells` WHERE
(`map_cells`.`id` = 51)
  MapCell Load (0.2ms)   SELECT * FROM `map_cells` WHERE
(`map_cells`.`id` = 52)
  MapCell Load (0.3ms)   SELECT * FROM `map_cells` WHERE
(`map_cells`.`id` = 61)
  MapCell Load (0.2ms)   SELECT * FROM `map_cells` WHERE
(`map_cells`.`id` = 62)

Rails führt für jede ID einen eigenen SELECT aus. Da das Array mit den
IDs locker mal 100 IDs enthalten kann, möchte ich das performanter
durchführen. Ideal wäre eine einzelne SQL-Abfrage.

Ist sowas mit Rails einfach realisierbar?

Viele Grüße,
Devillo
-- 
Posted via http://www.ruby-forum.com/.
_______________________________________________
rubyonrails-ug mailing list
[email protected]
http://mailman.headflash.com/listinfo/rubyonrails-ug

Antwort per Email an