I'm new to Grails and I'm stuck with this problem for hours. Thanks in advance for you help!
Here is my question:
I have a database with two tables
- PROJECT
- LIKES
As you can guess a user has the right to Like a Project. In the Domain Class Project there is NO relations (belongsTO, hasOne, etc..) Same in the Domain Class Likes
In the database the table LIKES has a field project_id but it is not set as a foreign_key. It is this made this way for right purpose.
Now I need to execute a native SQL query with grails which is really simple and returns the result expected.
The result is all projects that have Likes or not
Here is the query :
SELECT project.name, Likes.likes
FROM project
LEFT JOIN Likes
ON project.id = likes.project_id;
I cant find a way to convert this SQL query to HQL. It seems that HQL works on Domain instance and the fact that there is no relation between the domains return an error like "the Domain Project has no Likes attribute" which is correct.
Is there a way to get the right result with one query or do I need to do two query and build an Array with the result programmatically ?
Thanks for you help