[Cubicweb] Proposal: new method ResultSet.one()
afayolle.ml at free.fr
Thu Dec 5 14:34:56 CET 2013
On 04/12/2013 15:40, Christophe de Vienne wrote:
> I propose to add a new method to ResultSet, named one(), that would
> return exactly one entity from the resultset.
> If more than one row and one column, or no row at all is found, an
> exception would be raised.
> It would allow to write :
> entity = execute('SOME REQUEST').one()
> where right now we have to do :
> rset = execute('SOME REQUEST')
> if rset.rowcount != 1:
> # do something
> entity = rset.get_entity(0, 0)
> The idea is shamelessly borowed from SQLAlchemy Query.one() 
> I have a patch that propose an implementation, I can push it for review
> and discussion if you think it is worth it.
> PS: btw, I did not manage to run the cubicweb test suite, is there some
> things to be known to do so ?
> Cubicweb mailing list
> Cubicweb at lists.cubicweb.org
Would this be significantly different from calling next() on the rset ?
More information about the Cubicweb