I am new in using Datamapper ORM for Codeigniter, so I need some help. I am trying to do my own blog in CI with ORM. I have it written in classic CI Active record class, and there is a problem to write some queries in ORM syntax (or I do not know it and I need help). I have the blog, where are articles and they have comments. User can also vote the post. In classic CI AR I have this query:
$query = $this->db->select("
a.title AS articles_title, a.content AS articles_content,
CONCAT(up.first_name, ' ', up.last_name) AS articles_author,
DATE_FORMAT(a.created, '%T %d.%m.%Y') AS articles_created,
(SELECT IFNULL(ROUND(AVG(av.vote),1), 0) FROM articles_votes av WHERE a.id = av.article_id) AS articles_votes,
(SELECT COUNT(ac.id) FROM articles_comments ac
WHERE a.id = ac.article_id) AS articles_totalcomments", FALSE)
->join('user_profiles up', 'a.author_id = up.user_id')
This give me array with all informations I need. I only pass this array to view and show it. This query returns me author full name (from table profiles, not user - I use TankAuth), and it gives me counted comments, it also gives me average mark of voting. Is possible to make this in ORM? I need your help, please!