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.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---