Hey,
So, I've been working on a rebuild of a complex query (its a friendship style relationship between user accounts). Formerly it was stored using two tables (in addition to the user table), with three records total to represent a single relationship (yes, pretty horrible, and it is having a huge negative impact on our performance due to table bloat).
So, my solution was a single table that would store a single record for each relationship; however, this means that the default behavior in rails (of using a single foreign key in a has_many relationship) wasn't going to work. So, my finder actually looks like:
has_many :friends, :class_name => "User", :finder_sql =>
"SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
SELECT users.*, friends.position_one AS position FROM friends
LEFT OUTER JOIN users ON users.id = friends.person_two_id
WHERE friends.person_one_id = #{id}
UNION
SELECT users.*, friends.position_two AS position FROM friends
LEFT OUTER JOIN users ON users.id = friends.person_one_id
WHERE friends.person_two_id = #{id}
ORDER BY friends.position;
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;"
So, now onto the problem (well, it is possible that I'm just missing something and there is a way to do that type of relationship in Rails, but if there is then I'm either blind or its horribly obscure).
Whenever I try to call paginate on that function I get an error (see below), where the error is caused by the finder_sql being truncated to 128 characters.
The error log is located here
Any help is appreciated. I also realize that this may not even be a will_paginate bug, but something related to an issue within Rails or Ruby itself; however, I figured that starting with the plugins first would be the best place :)
Cheers and thanks,
James