ActiveRecords Associations preloader

Hi there ,

i'm trying to preload my associations like this :

@infos = ArchInformation.paginate_by_sql[sql_request], :page =>
params[:page], :per_page => nb_infos_per_page,
[:archive_arch_treatments, :archive_arch_contacts]).run

(sql_request containts something like this :

SELECT DISTINCT i.*,u.login, t.dossier_noaors, t.handle_date,,
AS nb_fichiers
FROM (((archive.information i
left join archive.treatments t on
left join public.users u on
left join archive.contacts c2 on
left join archive.fichiers_informations fi2 on
left join archive.contents c on = i.content_id
WHERE ((i.is_draft <> 1 AND is_draft <> -1)
OR i.is_draft is null) AND c2.type_contact_id = 1
AND (i.creation_date >= '2015-02-04 00:00:00 +0100' )
GROUP BY, u.login,t.dossier_noaors,t.handle_date, ORDER BY
creation_date DESC

and i get some result from it

now,here is my models :

class ArchInformation < ActiveRecord::Base
set_table_name 'archive.information'

has_one :archive_arch_treatments, :class_name => 'ArchTreatments'
has_many : archive_arch_contact, : class_name => 'ArchContacts'


class ArchContacts < ActiveRecord::Base
set_table_name 'archive.contacts'


class Archtreatments < ActiveRecord::Base
set_table°name 'archive.treatments'
belongs_to :archive_arch_information, :class_name =>"ArchInformation",
:foreign_key => "information_id"


and when i run this , i've got an error : here is the logs :

PG::UndefinedColumn: ERREUR: la colonne treatments.arch_information_id
n'existe pas
LINE 1: ..."treatments".* FROM "archive"."treatments" WHERE
: SELECT "archive"."treatments".* FROM "archive"."treatments" WHERE
"archive"."treatments"."arch_information_id" IN ('1885320', '1885319',
'1885318', '1885317', '1885316', '1885315', '1885314', '1885313')

the error is obvious , when activeRecord build the request , he named my
foreign key "arch_information_id" instead of "information_id" like i
told him in my ArchTreatments class

Why ? And how the fix it ?

Already thanks you

The preload is going from your ArchInformation to your archive_arch_treatments association - it is the foreign_key setting on this association that is used not the one “on the other side” (active record isn’t smart enough to apply options from one to the other)