Glorp join

11 views
Skip to first unread message

John McKeon

unread,
Oct 13, 2009, 3:53:02 PM10/13/09
to webve...@googlegroups.com
I have this strange behavior occuring that maybe someone more knowledgable about Glorp can pinpoint quickly from the symptom
I want to order my objects by sending: self paginator query orderBy: #(site id) where site is an object variable that holds an instance of the (OneToOneMapping) Site class which has, of course an id field.

The query generated is:
SELECT t1.id, t1.cntid, t1.qid, . . . t1.developer, t1.site, t1.status
FROM (dss.cnts t1 INNER JOIN dss.sites t1 ON (t1.site = t1.id)) ORDER BY t1.id LIMIT 30

Glorp correctly finds the JOIN table but refuses to give it an alias different than the table to which it is being JOINed.

Assuming it should come up with t2 for the alias of the dss.sites table, the FROM clause should read:
FROM (dss.cnts t1 INNER JOIN dss.sites t2 ON (t1.site = t2.id)) ORDER BY t2.id LIMIT 30

I have set up descriptors and tables for all my domain models (but not class models), I have gotten this orderBy: scheme to work on another application with another db.

Can someone point me in the right direction?
Thanks

John

--
http://jmck.seasidehosting.st

Alan Knight

unread,
Oct 13, 2009, 5:15:27 PM10/13/09
to webve...@googlegroups.com
Well that's just weird. So either it's not aliasing correctly, or else for some reason it thinks that that join is between the same two tables. What does the mapping look like?

John McKeon

unread,
Oct 13, 2009, 6:12:25 PM10/13/09
to webve...@googlegroups.com
On Tue, Oct 13, 2009 at 5:15 PM, Alan Knight <alan....@gmail.com> wrote:
Well that's just weird. So either it's not aliasing correctly, or else for some reason it thinks that that join is between the same two tables. What does the mapping look like?


The mapping for the site variable in the Cnt class is:
(aDescriptor newMapping: OneToOneMapping) attributeName: #site; referenceClass: Site.

Site's variables are id, site, description with appropriate DirectMapping's

Thanks for the help
John


On Tue, Oct 13, 2009 at 3:53 PM, John McKeon <p3an...@gmail.com> wrote:
I have this strange behavior occuring that maybe someone more knowledgable about Glorp can pinpoint quickly from the symptom
I want to order my objects by sending: self paginator query orderBy: #(site id) where site is an object variable that holds an instance of the (OneToOneMapping) Site class which has, of course an id field.

The query generated is:
SELECT t1.id, t1.cntid, t1.qid, . . . t1.developer, t1.site, t1.status
FROM (dss.cnts t1 INNER JOIN dss.sites t1 ON (t1.site = t1.id)) ORDER BY t1.id LIMIT 30

Glorp correctly finds the JOIN table but refuses to give it an alias different than the table to which it is being JOINed.

Assuming it should come up with t2 for the alias of the dss.sites table, the FROM clause should read:
FROM (dss.cnts t1 INNER JOIN dss.sites t2 ON (t1.site = t2.id)) ORDER BY t2.id LIMIT 30

I have set up descriptors and tables for all my domain models (but not class models), I have gotten this orderBy: scheme to work on another application with another db.

Can someone point me in the right direction?
Thanks

John

--
http://jmck.seasidehosting.st








--
http://jmck.seasidehosting.st

John McKeon

unread,
Oct 13, 2009, 6:34:11 PM10/13/09
to webve...@googlegroups.com
I think I need to add a where clause first with something like:
paginator query: (self class objectClass queryWhere: [ :each | eadh id notNil ]).

I can get a working set up to fail with the same error by removing that message send
prior to the orderBy: send. (In that case the query is set up with the default Query read: objectClass)

John
--
http://jmck.seasidehosting.st

John McKeon

unread,
Oct 14, 2009, 8:54:05 AM10/14/09
to webve...@googlegroups.com
This turns out to be my error. Instead of creating a new query object for the paginator, I try to set the existing query's ordering to nil: and then give it the new ordering.

paginator query setOrdering: nil.

paginator query orderBy: #(site id)

This apparently doesn't work so well =)
--
http://jmck.seasidehosting.st

James Robertson

unread,
Oct 14, 2009, 9:59:11 AM10/14/09
to webve...@googlegroups.com
Yeah, that bit me building the media search app too.

Alan Knight

unread,
Oct 14, 2009, 11:45:09 AM10/14/09
to webve...@googlegroups.com
Ah yes, don't try to reuse queries once they've been executed once. They compute and cache a whole bunch of information. You might be able to do a copy of the query and use that, but it's probably just as easy to make a new one.
Reply all
Reply to author
Forward
0 new messages