toamitkumar@gmail.com
2009-Jul-19 19:50 UTC
Joining and paginating output of 2 multiple models
We have 2 models... say for eg: Person and Contractor... Based on different criteria (office, department, interest etc) we need to show paginated result of both people and contractors which will be all sorted by name. Right now, the one solution is to put SQL query like: select * from ( select * from people where conditions union select * from contractors where same conditions ) order by name and then use the paginated plugin to take care of the collection returned by query. Since we are dealing with legacy database where I cannot club together both the models and create STI to make the code simpler. Is there any better approach for this problem... I am sure there...
On Jul 19, 12:50 pm, "toamitku...@gmail.com" <toamitku...@gmail.com> wrote:> We have 2 models... say for eg: Person and Contractor... Based on > different criteria (office, department, interest etc) we need to show > paginated result of both people and contractors which will be all > sorted by name. > > Right now, the one solution is to put SQL query like: > > select * from ( > select * from people where conditions > union > select * from contractors where same conditions > ) > order by name > > and then use the paginated plugin to take care of the collection > returned by query. > > Since we are dealing with legacy database where I cannot club together > both the models and create STI to make the code simpler. > > Is there any better approach for this problem... I am sure there...I suggest you ask this question on rubyonrails-talk http://groups.google.com/group/rubyonrails-talk This list is used for discussing the rails framework development, not rails implementation questions. -Mark