Closed davel closed 5 years ago
Could you tell me what is the actual value of the result prior you pass it to present
?
The object passed to present
is a DBIx::Class::ResultSet
.
I've added a search feature to your music demo app to demonstrate this, see my fork at https://github.com/davel/Raisin
Multiple results, array returned as expected,
curl -H "Accept: text/json" http://0:5000/artists?name=Green%
{"count":1,"data":[{"hash":"20","artist":"Green Day","id":2,"albums":[{"title":"39/Smooth","id":4,"year":1990},{"title":"Kerplunk","id":5,"year":1992},{"title":"Dookie","id":6,"year":1994},{"title":"Insomniac","id":7,"year":1995},{"title":"Nimrod","id":8,"year":1997},{"title":"Warning","id":9,"year":2000},{"title":"American Idiot","id":10,"year":2004},{"title":"21st Century Breakdown","id":11,"year":2009}]}]}
No results, null
returned rather than []
,
curl -H "Accept: text/json" http://0:5000/artists?name=asdf
{"count":0,"data":null}
I guess that happens because DBIx::Class's search
returns undef
.
I'll take a look at it later, or if you can dump the $artists
after https://github.com/davel/Raisin/blob/master/examples/music-app/script/music_app_dbix.psgi#L38 it would also be very helpful.
I thought that might be the case too. However, if $artists
was undef
, the call to $artists->count
on line 41 would fail. ref($artists)
confirms that it is a DBIx::Class::ResultSet
.
@davel could you verify #48 fixes your issue?
Yes, that fixes my problem, thank you.
If the result of a DBIx::Class query given to
present
returns no rows, the generated JSON isundef
, rather than an empty array. Can the behaviour be changed to make it return[]
, so as to make the behaviour consistent?Many thanks, Dave