# Join query

**URL:** <https://www.ruby-forum.com/t/join-query/133152>\
**Category:** Rails\
**Created:** [March 28, 2008, 10:54am UTC](https://www.ruby-forum.com/t/join-query/133152 "2008-03-28T10:54:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![subhadip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3d9bf3/32.png) [@subhadip](https://www.ruby-forum.com/u/subhadip)\
**Post date:** [March 28, 2008, 10:54am UTC](https://www.ruby-forum.com/t/join-query/133152/1 "2008-03-28T10:54:41Z")

</div>

hello i am new in ruby on rails…i will want to know how we write  
join query in ruby on rails,and how we define relationship  
between two tables in ruby on rails…(like belongs\_to,has\_many etc)  
can anyone provide simple code or url,its urgent…

---

<div class="post-metadata">

**Author:** ![subhadip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3d9bf3/32.png) [@subhadip](https://www.ruby-forum.com/u/subhadip)\
**Post date:** [March 28, 2008, 2:52pm UTC](https://www.ruby-forum.com/t/join-query/133152/2 "2008-03-28T14:52:43Z")

</div>

Subhadip Chakraborty wrote:

> hello i am new in ruby on rails…i will want to know how we write  
> join query in ruby on rails,and how we define relationship  
> between two tables in ruby on rails…(like belongs\_to,has\_many etc)  
> can anyone provide simple code or url,its urgent…

At some point, you need to break down and actually “READ” something on  
Ruby on Rails… there are a bazillion tutorials out there that walk  
through the basics, including parent-child relationships and how to use  
them…

# Table name: projects

# 

# id :integer(11) not null, primary key

# proj\_name :string(30) default(""), not null

# proj\_desc :string(60)

# proj\_text :text

class Project \< ActiveRecord::Base  
has\_many :scenarios  
end

# Table name: scenarios

# 

# id :integer(11) not null, primary key

# scen\_name :string(30) default(""), not null

# scen\_text :text

# project\_id :integer(11)

class Scenario \< ActiveRecord::Base  
belongs\_to :project  
end

A Project claims to have many Scenarios.  
A Scenario has an element project\_id, hence the scenarios for a project  
can be found because the Scenario has a field called project\_id which  
points to its parent.
