DataMapper和find_by_sql问题

时间:2011-08-09 17:15:33

标签: ruby orm datamapper find-by-sql

Player.find_by_sql(["SELECT u.id, u.name, UNIX_TIMESTAMP(u.last_active) AS last_active, TIME_TO_SEC(TIMEDIFF(NOW(), u.last_active)) AS time_difference, r.status, SUM(d.amount) AS gold_spent, SUM(d2.amount) AS points_spent
FROM players u
LEFT JOIN guild_ranks r ON r.player_id=u.id AND r.guild_id=u.guild_id
LEFT JOIN guild_donations d ON d.player_id=u.id AND d.guild_id=u.guild_id AND d.type=1
LEFT JOIN guild_donations d2 ON d2.player_id=u.id AND d2.guild_id=u.guild_id AND d2.type=2
WHERE u.guild_id=? ORDER BY r.status, u.level DESC", guild]

如何让返回的DataMapper :: Collection也包含gold_spent和points_spent以及time_difference?

gold_spent,points_spent和time_difference 应该是属性(还是有办法让它们只是DM属性而不是数据库中的内容?)

0 个答案:

没有答案