Mixing joins and include conflicts

I have found that Rails doesn't works well when mixing joins and
includes. For example I have the following models: Event, Attendance
and User.

class Event < ActiveRecord::Base

# User that creates the event
belongs_to :created_by,
           :select => "id, name, lastname",
           :foreign_key => "user_id",
           :class_name => "User"
has_many :attendances
has_many :users, :through => :attendances

As you can see the query sort of works, but not in the way it should.
A lot of aliases are created, the include is treated as a LEFT OUTER
JOIN and more columns are selected than the ones I specify. So well,
here I leave it and hope someone has noticed this too so we can work
on it.

That's how include works when it thinks you are referencing included
tables. unfortunately it doesn't scan the joins clause and so it
thinks its needs to use the joins version of :include.

Fred

Are there any plans to solve this issue? How can anyone work around
this problem? Imagine I want to include also the pictures related to
the events, event_category etc...What approach should someone take?
The query generated is far from what it should be. Thanks,

Elioncho

Are there any plans to solve this issue? How can anyone work around
this problem? Imagine I want to include also the pictures related to
the events, event_category etc...What approach should someone take?
The query generated is far from what it should be. Thanks,

The key thing is that it is hard to parse the joins fragment. In terms
of plans to fix it, I'm sure a patch fixing this would be welcomed.
It may be more practical in your case to do this in two goes, ie
locate the relevant events and then do Event.find
some_list_of_ids, :include => ...
ANother thing I've been playing around with is the ability to do

events = Event.find(:joins => ...)
events.load :created_by

(I've got a highly experimental plugin that implements this: http://github.com/fcheung/ar_result_set/tree/master
   i haven't had time to do much with it recently)

Fred

Thanks Fred,

I'll look into it. Its good to know I am not alone on this issues.

Elioncho