Moved the query code from the controller to the base Model class