added ability to segment sort orders by a foreign key