# Habtm & STI question

**URL:** <https://www.ruby-forum.com/t/habtm-sti-question/121939>\
**Category:** Rails\
**Created:** [December 3, 2007, 4:43am UTC](https://www.ruby-forum.com/t/habtm-sti-question/121939 "2007-12-03T04:43:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![BJ\_ClarkSthe\_scie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e47774/32.png) [@BJ\_ClarkSthe\_scie](https://www.ruby-forum.com/u/BJ_ClarkSthe_scie)\
**Post date:** [December 3, 2007, 4:43am UTC](https://www.ruby-forum.com/t/habtm-sti-question/121939/1 "2007-12-03T04:43:36Z")

</div>

Hello All,  
I have a model “Company”

class Company \< ActiveRecord::Base  
has\_and\_belongs\_to\_many :types  
end

And I also have MachineType and CompanyType that STI from the “Type”  
model.

I have both a MachineType id and a CompanyType id and I want to get  
all companies that have both of those types.  
Is there a way similar to something like this:

@companies =  
MachineType.find(params[:type]).companies.types.find(@type) ?

I’m just trying to figure out how to do this type of thing without  
some nasty joins.

Thanks!

BJ Clark  
the science department.
