# Doubt retrieving data?

**URL:** <https://www.ruby-forum.com/t/doubt-retrieving-data/173415>\
**Category:** Rails\
**Created:** [August 8, 2009, 9:42am UTC](https://www.ruby-forum.com/t/doubt-retrieving-data/173415 "2009-08-08T09:42:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![karthik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/9fc348/32.png) [@karthik](https://www.ruby-forum.com/u/karthik)\
**Post date:** [August 8, 2009, 9:42am UTC](https://www.ruby-forum.com/t/doubt-retrieving-data/173415/1 "2009-08-08T09:42:46Z")

</div>

hi

my controller has

def searchwithstatus  
@agency=params[:agency][:agency\_id]  
@contract=params[:agency][:contracts\_id]  
@agencies=Agency.find(:all,:conditions=\>{:deleted=\>1,:contract\_id=\>@contract,:state\_id=\>@state})  
end

when i am executing the code in line 3 it is saying as

\*“Mysql::Error: Unknown column ‘agencies.contract\_id’ in ‘where  
clause’: SELECT \* FROM `agencies`  
WHERE (`agencies`.`state_id` = ‘1’ AND `agencies`.`contract_id` = ‘13’  
AND `agencies`.`deleted` = 1) \*”

_how can i access the contract\_id which is in another table_

## please help

Karthik.k  
Mobile - +91-9894991640

---

<div class="post-metadata">

**Author:** ![karthik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/9fc348/32.png) [@karthik](https://www.ruby-forum.com/u/karthik)\
**Post date:** [August 8, 2009, 10:17am UTC](https://www.ruby-forum.com/t/doubt-retrieving-data/173415/2 "2009-08-08T10:17:16Z")

</div>

Karthik Kantharaj wrote:  
#\> _how can i access the contract\_id which is in another table_

:contract\_id=\>"#{@contract.id}"

---

<div class="post-metadata">

**Author:** ![karthik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/9fc348/32.png) [@karthik](https://www.ruby-forum.com/u/karthik)\
**Post date:** [August 8, 2009, 10:44am UTC](https://www.ruby-forum.com/t/doubt-retrieving-data/173415/3 "2009-08-08T10:44:13Z")

</div>

On Sat, Aug 8, 2009 at 1:47 PM, James W.  
\<removed\_email\_address@domain.invalid

> wrote:

> Karthik Kantharaj wrote:  
> #\> _how can i access the contract\_id which is in another table_
> 
> :contract\_id=\>"#{@contract.id}"

hi James W.

Thank you

@agencies=Agency.find(:all,:conditions=\>{:deleted=\>1,:contract\_id  
=\>@contract,:state\_id=\>@state})

but i am not able to access :contract\_id because there is no field of  
contract\_id  
in agencies table

agencies and contracts contains habtm relation

i am passing this from

\<% form\_remote\_tag(:update =\>“searchagencies”,:url =\> {:action =\>  
:searchwithstatus}) do%\>

| Contract | \<%= collection\_select(:agency,:contracts\_id,@contracts,:id,:name,{:include\_blank =\>'All'}) %\> |
| --- | --- |

 \<% end%\>

I need to know how to access the :contract\_id  
and match with the contract\_id in contract table and need to search
