Accessing columns with custom SQL

Discuss about Group-Office development here

Moderator: Developers

jamesarthur
Posts: 55
Joined: Fri Nov 08, 2013 9:15 am

Accessing columns with custom SQL

Postby jamesarthur » Thu Mar 06, 2014 2:45 pm

Hi

I have a query which joins another table and then filters it down so there is a 1-1 relationship. An example: I have something like

Code: Select all

SELECT t.id, 
t.something as something
...
other.id as other@id
other.something as other@something
...
FROM table t
INNER JOIN other ON other.table_id = table.id
WHERE 1 AND NOT EXISTS (
  SELECT null FROM other other2 WHERE other2.start > other.start
)
My question is: since the results are mapped to a class, I don't know how to get at the 'other.id AS other@id' type variables. I've tried things like getAttribute('other@id') but that doesn't work. Do you have any hints?
mschering
Site Admin
Site Admin
Posts: 8281
Joined: Tue Apr 20, 2004 1:06 pm
Location: The Netherlands - Den Bosch
Contact:

Re: Accessing columns with custom SQL

Postby mschering » Fri Mar 07, 2014 12:59 pm

other must be a relation. They will create the other relation automatically.

So it's

$model->other->id
Best regards,

Merijn Schering
Intermesh
jamesarthur
Posts: 55
Joined: Fri Nov 08, 2013 9:15 am

Re: Accessing columns with custom SQL

Postby jamesarthur » Fri Mar 07, 2014 2:19 pm

What if there can't be a relation representing the data? For example the above is a 1-1 relation, but it doesn't have id's in each table.
mschering
Site Admin
Site Admin
Posts: 8281
Joined: Tue Apr 20, 2004 1:06 pm
Location: The Netherlands - Den Bosch
Contact:

Re: Accessing columns with custom SQL

Postby mschering » Mon Mar 10, 2014 9:51 am

If you join anything else the attributes will be loaded as well. But don't use '@' signs in the aliases.
Best regards,

Merijn Schering
Intermesh

Who is online

Users browsing this forum: No registered users and 1 guest