# ActiveRecord Limitation (Advance)

**URL:** <https://www.ruby-forum.com/t/activerecord-limitation-advance/111061>\
**Category:** Rails\
**Created:** [August 2, 2007, 9:04am UTC](https://www.ruby-forum.com/t/activerecord-limitation-advance/111061 "2007-08-02T09:04:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nigel.bris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e95f7d/32.png) [@nigel.bris](https://www.ruby-forum.com/u/nigel.bris)\
**Post date:** [August 2, 2007, 9:04am UTC](https://www.ruby-forum.com/t/activerecord-limitation-advance/111061/1 "2007-08-02T09:04:13Z")

</div>

Or is it ?

Need to be able to :-

@search =  
Form.find(:all, :include=\>[:form\_type, :form\_type\_items],  
:conditions=\>…)

I need in the Form model a :form\_type\_items, the question is, what is  
the relationship type?

Current Models:-  
Form  
belongs\_to :form\_type

FormType  
has\_many :form\_types  
has\_many :form\_type\_items

FormTypeItem  
Belongs\_to :form\_type

## Form

| id |
| --- |
| form\_type\_id |

* * *

## FormType

| id |
| --- |
| name |

* * *

## FormTypeItem

| id |
| --- |
| form\_type\_id |

* * *

| title |
| --- |

---

<div class="post-metadata">

**Author:** ![nigel.bris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e95f7d/32.png) [@nigel.bris](https://www.ruby-forum.com/u/nigel.bris)\
**Post date:** [August 2, 2007, 12:27pm UTC](https://www.ruby-forum.com/t/activerecord-limitation-advance/111061/2 "2007-08-02T12:27:40Z")

</div>

Form  
belongs\_to :form\_type  
has\_many :form\_type\_items, :through =\> :form\_type

On 8/2/07, nigel.bris [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> | id |
> 
> | title |
> | --- |
> 
> >

–  
Cheers!

- Pratik  
[http://m.onkey.org](http://m.onkey.org)

---

<div class="post-metadata">

**Author:** ![nigel.bris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e95f7d/32.png) [@nigel.bris](https://www.ruby-forum.com/u/nigel.bris)\
**Post date:** [August 3, 2007, 12:10am UTC](https://www.ruby-forum.com/t/activerecord-limitation-advance/111061/3 "2007-08-03T00:10:31Z")

</div>

Unfortunately, that code fails with:-

Mysql::Error: #42S22Unknown column ‘form\_types.form\_type\_id’ in ‘on  
clause’

as this is not a:-

pk\<-(fk/fk)-\>pk relationship.

its a fk-\>(pk)\<-fk, any ideas what the relationship type is in that  
case?

Thanks

---

<div class="post-metadata">

**Author:** ![nigel.bris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e95f7d/32.png) [@nigel.bris](https://www.ruby-forum.com/u/nigel.bris)\
**Post date:** [August 3, 2007, 12:45am UTC](https://www.ruby-forum.com/t/activerecord-limitation-advance/111061/4 "2007-08-03T00:45:57Z")

</div>

nigel.bris wrote:

> Need to be able to :-
> 
> @search =  
> Form.find(:all, :include=\>[:form\_type, :form\_type\_items],  
> :conditions=\>…)

What error message do you get with that? Try it with hash (worked for  
me):  
Form.find(:all, :include =\> {:form\_type =\> :form\_type\_items})

---

<div class="post-metadata">

**Author:** ![nigel.bris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e95f7d/32.png) [@nigel.bris](https://www.ruby-forum.com/u/nigel.bris)\
**Post date:** [August 3, 2007, 7:50am UTC](https://www.ruby-forum.com/t/activerecord-limitation-advance/111061/5 "2007-08-03T07:50:05Z")

</div>

Worked Perfectly!

You guys are guru’s…

Ps… Didn’t know that hash inside include feature, rails amazes me  
more everyday!

Thanks!

On Aug 3, 8:45 am, Dondi S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
