sequelize/sequelize — pull request #1678 by cusspvz (2014-04-23 15:34:19+00:00)
Title: Test Unit for another require bug

As sequelize don't provide yet the API for polymorphy i have to use a lot of `where` and `required` options.

In result of that i found a bug and tried to make an example test unit.

Original generated queries (from my app):
```mysql
# This returns a total count of 10
SELECT COUNT(`Place`.`id`) as `count` FROM `Place` AS `Place` INNER JOIN `Associate` AS `Associates` ON `Place`.`id` = `Associates`.`foreign_key` AND `Associates`.`model`='Place' AND `Associates`.`user_id`=5 AND `Associates`.`deleted_at` IS NULL WHERE `Place`.`deleted_at` IS NULL;

# This returns 3 rows
SELECT `Place`.*, `Associates`.`id` AS `Associates.id`, `Associates`.`id` AS `Associates.id` FROM (SELECT `Place`.* FROM `Place` AS `Place` WHERE `Place`.`deleted_at` IS NULL AND (SELECT `foreign_key` FROM `Associate` AS `Associates` WHERE `Place`.`id` = `Associates`.`foreign_key` LIMIT 1) IS NOT NULL LIMIT 10) AS `Place` INNER JOIN `Associate` AS `Associates` ON `Place`.`id` = `Associates`.`foreign_key` AND `Associates`.`model`='Place' AND `Associates`.`user_id`=5 AND `Associates`.`deleted_at` IS NULL;
```

I spoted 2 problems over here:
* the first one might be on secundary subQuery, since include conditions aren't there it doesn't filter correctly.
* the second one is caused by the first one, as the subQuery is limited by 10 it only passes 3 rows because they were the ones that matched the `INNER JOIN` conditions.

Here are three screenshots of data retrieved by: first query, second query, subQuery of second query.

![captura de ecra 2014-04-23 as 16 33 21](https://cloud.githubusercontent.com/assets/3604053/2779506/b9882136-cafc-11e3-8539-a806f16a9f40.png)
![captura de ecra 2014-04-23 as 16 32 53](https://cloud.githubusercontent.com/assets/3604053/2779505/b987c696-cafc-11e3-8038-5e41d7ba9548.png)
![captura de ecra 2014-04-23 as 16 32 36](https://cloud.githubusercontent.com/assets/3604053/2779507/b988d19e-cafc-11e3-9361-3182fa7623da.png)