示例#1
0
func (s *RethinkSuite) TestOrderByJoinEq(c *test.C) {
	type Map map[string]interface{}
	var err error

	// Ensure table + database exist
	DBCreate("test").Exec(session)
	DB("test").TableCreate("test").Exec(session)
	DB("test").TableCreate("test2").Exec(session)
	tab := DB("test").Table("test")
	tab2 := DB("test").Table("test2")

	// insert rows
	err = tab.Insert(Map{"S": "s1", "T": 2}).Exec(session)
	err = tab.Insert(Map{"S": "s1", "T": 1}).Exec(session)
	err = tab.Insert(Map{"S": "s1", "T": 3}).Exec(session)
	err = tab.Insert(Map{"S": "s2", "T": 3}).Exec(session)
	c.Assert(err, test.IsNil)

	err = tab2.Insert(Map{"id": "s1", "N": "Rob"}).Exec(session)
	err = tab2.Insert(Map{"id": "s2", "N": "Zar"}).Exec(session)
	c.Assert(err, test.IsNil)

	// Test query
	var response []Map
	res, err := tab.OrderBy("T").EqJoin("S", tab2).Run(session)
	c.Assert(err, test.IsNil)

	err = res.All(&response)
	c.Assert(err, test.IsNil)
	c.Check(len(response), test.Equals, 4, test.Commentf("%v", response))
}