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…
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.