Rails: foreign_key that is set with a CASE WHEN mysql statement

Posted by user305270 on Stack Overflow See other posts from Stack Overflow or by user305270
Published on 2010-03-31T00:11:13Z Indexed on 2010/03/31 0:13 UTC
Read the original article Hit count: 703

Filed under:
  belongs_to :removed_friend, 
      :class_name => 'Profile', 
      :foreign_key => "(CASE WHEN friendships.profile_id = #{self.id} THEN friendships.friend_id ELSE friendships.profile_id END)"

The self.id its not working too :s it should be the id of the profile that is triggered the action.

Anyway the main problem is that this foreign_key is not working and i got a mysql error.

please help.. thanks

© Stack Overflow or respective owner

Related posts about rails