#519 ✓resolved

Asking children of a new record results in a query

Reported by Ewout | August 7th, 2008 @ 08:47 AM

s = Selection.new s.baskets << Basket.new

logs: Thu, 07 Aug 2008 12:47:32 GMT ~ debug ~ SELECT "id", "title", "annotation", "selectionid" FROM "baskets" WHERE "selectionid" IN (NULL) ORDER BY "id"

Both Selection and Basket are models with a serial id.

There could be some cases where it is ok to launch a query asking for the associated children of a new resource: when the resource has a natural key and it already exists in the datastore.

The latter is a doubtful scenario however: saving the new resource if it already exists in the datastore will yield an error.

In any case, performing a query to find associated children of a new resource with an empty serial key is just overhead.

I included a patch that covers this case. Maybe it can be made more general, for example to never launch a query when the parent is a new_record.

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »