.with() on a .get() that returns no entities will throw a SQL error

Description

Quick 2.5.4, qb 7:

If you have a scope or some query logic that returns an empty recordset, but attach a with() call, e.g.

QB will throw an error because it is trying to run a query like:

Environment

None

Activity

Show:
Eric Peterson
December 31, 2019, 4:59 AM

I’m going to need more than this. I tried to add a test to show this failing and I couldn’t get the test to fail for both a belongsTo and a hasMany relationship.

Samuel W. Knowlton
December 31, 2019, 4:00 PM

I’m not able to reproduce this manually either. The bug report we have uses a scope, a .select(), and .with(). Here’s the Stack trace just in case this pops up again:

 

 

Samuel W. Knowlton
January 2, 2020, 8:36 PM

Figured this out:

If you specify a .select() when instantiating a Quick entity, it looks like it has to be an array of field names. We had some code that was supplying a comma-delimited list, e.g.

.select( “firstname”, “ID”)

This will not throw an exception but it will only select firstname. When it goes to eager load the attached records, it sees a null ID and that’s why it threw this exception.

Presumably a comma-delimited string for .select() used to work but does not any longer.

Eric Peterson
January 2, 2020, 8:45 PM

Did you install qb 7 manually? That was a breaking change in qb 7, but it shouldn’t install automatically for Quick 2.*. Also, a comma-delimited string still works (select( "one,two")), but variadic parameters do not (select( “one”, “two” )).

Samuel W. Knowlton
January 2, 2020, 9:55 PM

Yes, we did. I even saw that note but didn’t realize we were using variadic parameters until I went back and looked at it.

Assignee

Eric Peterson

Reporter

Samuel W. Knowlton

Labels

None

Priority

Major
Configure