skinny-framework/skinny-framework — pull request #214 by riverpuro (2014-12-17 16:21:45+00:00)
Title: Add limit clause to ORM FinderFeature findBy

FinderFeatureWithId#findBy throws scalikejdbc.TooManyRowsException when select * from table_name where ... returns 2 rows.

```
val m = Member.defaultAlias
val member = Member.findBy(
sqls.eq(m.countryId, 1)
.and.eq(m.companyId, 2)
.and.eq(m.mentorId, 3))

[info] - should have #findBy(where) *** FAILED ***
[info] scalikejdbc.TooManyRowsException:
[info] at scalikejdbc.RelationalSQLResultSetOperations$class.toSingle(RelationalSQL.scala:29)
[info] at scalikejdbc.OneToManies2SQLToOption.toSingle(OneToManies2SQL.scala:120)
[info] at scalikejdbc.OneToManies2SQLToOption$$anonfun$apply$14.apply(OneToManies2SQL.scala:132)
[info] at scalikejdbc.OneToManies2SQLToOption$$anonfun$apply$14.apply(OneToManies2SQL.scala:132)
[info] at scalikejdbc.RelationalSQLResultSetOperations$class.executeQuery(RelationalSQL.scala:38)
[info] at scalikejdbc.OneToManies2SQLToOption.executeQuery(OneToManies2SQL.scala:120)
[info] at scalikejdbc.OneToManies2SQLToOption.apply(OneToManies2SQL.scala:132)
[info] at skinny.orm.feature.FinderFeatureWithId$class.findBy(FinderFeature.scala:118)
[info] at skinny.orm.Member$.findBy(models.scala:22)
[info] at skinny.orm.SkinnyORMSpec$$anonfun$5$$anonfun$apply$mcV$sp$6.apply(SkinnyORMSpec.scala:128)
[info] ...
```

It may be bad where clause condition, but the behavior is too strict... I expect ActiveRecord::Base.find_by like behavior. It selects 1 record only (loosely a little bit).

```
Member.find_by(country_id: 1, company_id: 2, mentor_id: 3)
# Member Load (8.3ms) SELECT `members`.* FROM `members` WHERE `members`.`country_id` = 1 AND `members`.`company_id` = 2 AND `members`.`mentor_id` = 3 LIMIT 1
#=> #
```