I want an equivalent of buildDataObjectSet in SS3.6 to solve this challenge

33 views
Skip to first unread message

padbor

unread,
Aug 1, 2017, 6:22:39 AM8/1/17
to SilverStripe Core Development
I want an equivalent of buildDataObjectSet in SS3.6 to solve this challenge:
$sql = "
SELECT 
`News`.*,
Match(News.Title) Against('$q' IN BOOLEAN MODE) as titleTotal,
Match(News.Content) Against('$q' IN BOOLEAN MODE) as contentTotal
FROM
`News`
LEFT JOIN `NewsSiteURL` as siteURL
ON 
siteURL.`ID` = `News`.`mySiteURLID`
WHERE

Match(News.Title) Against('$q' IN BOOLEAN MODE) 
OR
Match(News.Content) Against('$q' IN BOOLEAN MODE)
ORDER BY
`Created` DESC, titleTotal +contentTotal DESC
LIMIT $limit
";
if($reponse = @DB::query($sql)){
$news = singleton('News')->buildDataObjectSet($reponse);
}
else{
$news = null;
}

padbor

unread,
Aug 3, 2017, 5:15:36 AM8/3/17
to SilverStripe Core Development
I was able to solve this in this way

$sql = "
SELECT 
`News`.`ID`,
Match(News.Title) Against('$q' IN BOOLEAN MODE) as titleTotal,
Match(News.Content) Against('$q' IN BOOLEAN MODE) as contentTotal
FROM
`News`
WHERE

Match(News.Title) Against('$q' IN BOOLEAN MODE) 
OR
Match(News.Content) Against('$q' IN BOOLEAN MODE)
ORDER BY
`Created` DESC, titleTotal +contentTotal DESC
LIMIT $limit
";
if($reponse = @DB::query($sql)){
$tab = [];
foreach($reponse as $one){
array_push($tab, $one["ID"]);
}

$news = News::get()->where("`News`.`ID` IN (". implode(',', $tab).  ")") ;
}
else{
$news = null;
}
 

Patrick Nelson

unread,
Aug 3, 2017, 9:08:25 PM8/3/17
to silverst...@googlegroups.com
Just FYI, be careful -- your code could be vulnerable to SQL injection. Be sure to use parameterization when putting variables in your raw SQL queries.

--
You received this message because you are subscribed to the Google Groups "SilverStripe Core Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to silverstripe-dev+unsubscribe@googlegroups.com.
To post to this group, send email to silverstripe-dev@googlegroups.com.
Visit this group at https://groups.google.com/group/silverstripe-dev.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages