Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent behavior of present when no rows are found #47

Closed
davel opened this issue Sep 21, 2018 · 6 comments
Closed

Inconsistent behavior of present when no rows are found #47

davel opened this issue Sep 21, 2018 · 6 comments

Comments

@davel
Copy link
Contributor

davel commented Sep 21, 2018

If the result of a DBIx::Class query given to present returns no rows, the generated JSON is undef, rather than an empty array. Can the behaviour be changed to make it return [], so as to make the behaviour consistent?

Many thanks,
Dave

@khrt
Copy link
Owner

khrt commented Sep 23, 2018

Could you tell me what is the actual value of the result prior you pass it to present?

davel added a commit to davel/Raisin that referenced this issue Sep 24, 2018
In order to demonstrate khrt#47
@davel
Copy link
Contributor Author

davel commented Sep 24, 2018

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}

@khrt
Copy link
Owner

khrt commented Sep 24, 2018

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.

@davel
Copy link
Contributor Author

davel commented Sep 24, 2018

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.

@khrt
Copy link
Owner

khrt commented Sep 24, 2018

@davel could you verify #48 fixes your issue?

@davel
Copy link
Contributor Author

davel commented Sep 24, 2018

Yes, that fixes my problem, thank you.

@khrt khrt closed this as completed in #48 Sep 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants