Hi there,
Ok taking my first steps into the world of SS3 (just when i start to get to grips with 2.4) i have a need to list all the items from one table [bScore that is linked to the table [bProject with a many many link, and show all the fields in the table 'Score' and if they have been associated with the table [bProject.
The function below ProjectScore is similar to a query i did a while back in 2.4 and it worked fine, i'm now trying to use similar SQL code and in SS3 it doesnt seem to like it, i get a [Warning] mysqli::query() [mysqli.query]: Empty query message. Am i still able to run this kinda function under SS3 or do i need to tweak, or is there a better way of doing it?
Below is the code and i have attached a picture with what I'm trying to do, each of the boxes are part of table Score, i want to show them all and then also show the ones that are associated with the project(the ones with 'Yes' and in red).
class Score extends DataObject {
public static $db = array(
'Title' => 'Varchar',
'Value' => "Enum('0,1,2,3,4,5','0')",
);
public static $belongs_many_many = array(
'Projects' => 'Project'
);
class Project extends DataObject {
public static $db = array(
'Title' => 'Varchar()',
'ShortDescription' => 'Varchar(70)',
'Description' => 'HTMLText',
'Status' => "Enum('Active, Completed, Cancelled, Suspended, Standby, Deleted', 'Active')",
'Type' => "Enum('Client, Internal, Private, Idea, N.A.', 'N.A.')",
'Priority' => "Enum('A. (High), B. (Medium), C. (Low), N.A.', 'N.A.')",
'DueDate' => 'Date'
);
public static $has_one = array(
'Owner' => 'Member',
'Requester' => 'Member'
);
public static $has_many = array(
'Tasks' => 'Task'
);
public static $many_many = array(
'Scores' => 'Score'
);
}
public function ProjectScore() {
$sqlQuery = new SQLQuery();
$sqlQuery->selectField = array('*');
$sqlQuery->setFrom = array("Project LEFT OUTER JOIN Project_scores on Project.ID = Project_scores.ProjectID LEFT JOIN Score on Project_scores.ScoreID = Score.ID ");
$sqlQuery->setGroupby = '';
$rawSQL = $sqlQuery->sql();
// execute and return a Query-object
$result = $sqlQuery->execute();
//setup our blank DataObjectSet to push SQL result data into it.
$dos = singleton('Scores')->buildDataObjectSet($result);
return $dos;
}
Any help or pointers?
Regards
Mick