# Find :include broken when upgrading to 2.2.2

**URL:** <https://www.ruby-forum.com/t/find-include-broken-when-upgrading-to-2-2-2/169499>\
**Category:** Rails\
**Created:** [June 4, 2009, 2:19pm UTC](https://www.ruby-forum.com/t/find-include-broken-when-upgrading-to-2-2-2/169499 "2009-06-04T14:19:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bobm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9fc348/32.png) [@bobm](https://www.ruby-forum.com/u/bobm)\
**Post date:** [June 4, 2009, 2:19pm UTC](https://www.ruby-forum.com/t/find-include-broken-when-upgrading-to-2-2-2/169499/1 "2009-06-04T14:19:52Z")

</div>

Hi, I’m upgrading an old 1.2 application to latest 2.2 and I got an  
error which is certainly due to :include

@factures = Facture.find(:all, :include =\> [[:forfait =\> :vehicule] =\>  
:client], :conditions =\> [“MONTH(factures.date\_emission) = ? AND  
YEAR(factures.date\_emission) = ?”, @mois, @annee], :order =\>  
‘clients.nom’)

This code produces an error

You have a nil object when you didn’t expect it!  
The error occurred while evaluating nil.macro

Does the :include option have changed its behaviour?

However the above line of code generate a valid SQL statement, run it  
but fails after.

SELECT `factures`.`id` AS t0\_r0, `factures`.`forfait_id` AS t0\_r1,  
`factures`.`titre` AS t0\_r2, `factures`.`date_emission` AS t0\_r3,  
`factures`.`date_envoyee` AS t0\_r4, `factures`.`date_payee` AS t0\_r5,  
`forfaits`.`id` AS t1\_r0, `forfaits`.`vehicule_id` AS t1\_r1,  
`forfaits`.`genre` AS t1\_r2, `forfaits`.`periodicite_reglement` AS  
t1\_r3, `forfaits`.`date_debut` AS t1\_r4, `forfaits`.`date_fin` AS t1\_r5,  
`forfaits`.`en_cours` AS t1\_r6, `vehicules`.`id` AS t2\_r0,  
`vehicules`.`client_id` AS t2\_r1, `vehicules`.`immatriculation` AS  
t2\_r2, `vehicules`.`marque` AS t2\_r3, `vehicules`.`modele` AS t2\_r4,  
`vehicules`.`veh_type` AS t2\_r5, `vehicules`.`num_serie` AS t2\_r6,  
`vehicules`.`couleur` AS t2\_r7, `vehicules`.`puissance` AS t2\_r8,  
`vehicules`.`date_pmec` AS t2\_r9, `vehicules`.`date_ct` AS t2\_r10,  
`vehicules`.`active` AS t2\_r11, `vehicules`.`created_at` AS t2\_r12,  
`vehicules`.`notes` AS t2\_r13, `vehicules`.`emplacement` AS t2\_r14,  
`clients`.`id` AS t3\_r0, `clients`.`nom` AS t3\_r1, `clients`.`prenom` AS  
t3\_r2, `clients`.`adresse` AS t3\_r3, `clients`.`email` AS t3\_r4,  
`clients`.`created_at` AS t3\_r5, `clients`.`notes` ASt3\_r6,  
`clients`.`periodicite_reglement` AS t3\_r7 FROM `factures` LEFT OUTER  
JOIN `forfaits` ON `forfaits`.id = `factures`.forfait\_id LEFT OUTER JOIN  
`vehicules` ON `vehicules`.id = `forfaits`.vehicule\_id LEFT OUTER JOIN  
`clients` ON `clients`.id = `vehicules`.client\_id WHERE  
(MONTH(factures.date\_emission) = 6 AND YEAR(factures.date\_emission) =  
2009) ORDER BY clients.nom

Any help appreciated, thanks

---

<div class="post-metadata">

**Author:** ![bobm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9fc348/32.png) [@bobm](https://www.ruby-forum.com/u/bobm)\
**Post date:** [June 4, 2009, 3:35pm UTC](https://www.ruby-forum.com/t/find-include-broken-when-upgrading-to-2-2-2/169499/2 "2009-06-04T15:35:27Z")

</div>

On Jun 4, 1:19 pm, Bob M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> You have a nil object when you didn’t expect it!  
> The error occurred while evaluating nil.macro
> 
> Does the :include option have changed its behaviour?

It did change slightly. I suspect that you originally got lucky: your  
include clause is

[[:forfait =\> :vehicule] =\> :client]

which ruby parses as  
[{[{:forfait=\>:vehicule}]=\>:client}]

which isn’'t the type of structure that rails is expecting (but  
obviously happened to work in the past). It looks like what you should  
be saying is

{:forfait =\> {:vehicule =\> :client}}

Fred

---

<div class="post-metadata">

**Author:** ![bobm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9fc348/32.png) [@bobm](https://www.ruby-forum.com/u/bobm)\
**Post date:** [June 5, 2009, 10:40am UTC](https://www.ruby-forum.com/t/find-include-broken-when-upgrading-to-2-2-2/169499/3 "2009-06-05T10:40:42Z")

</div>

Frederick C. wrote:

> On Jun 4, 1:19ï¿½pm, Bob M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > You have a nil object when you didn’t expect it!  
> > The error occurred while evaluating nil.macro
> > 
> > Does the :include option have changed its behaviour?
> 
> It did change slightly. I suspect that you originally got lucky: your  
> include clause is
> 
> [[:forfait =\> :vehicule] =\> :client]
> 
> which ruby parses as  
> [{[{:forfait=\>:vehicule}]=\>:client}]
> 
> which isn’'t the type of structure that rails is expecting (but  
> obviously happened to work in the past). It looks like what you should  
> be saying is
> 
> {:forfait =\> {:vehicule =\> :client}}
> 
> Fred

Thanks a lot Fred ! It’s always sensible when somebody gives you the  
solution 😉  
Have a nice day
