Table Relationship Reference Ruby on Rails -
i working on web application contractor (electrician, roofer, plumber) etc can make proposal online. pictures, youtube videos of project, , text description provided contractor customer.
so far working on pictures feature using carrierwave
this table of model in schema
create_table "project_pictures", force: true |t| t.string "name" t.string "picture" t.datetime "created_at" t.datetime "updated_at" end
here 2 records in rails console
projectpicture load (0.4ms) select "project_pictures".* "project_pictures" => #<activerecord::relation [#<projectpicture id: 2, name: "request siding quote customer a", picture: "siding.jpg", created_at: "2013-08-15 16:10:22", updated_at: "2013-08-15 16:47:02">, #<projectpicture id: 1, name: "request siding quote customer a", picture: "sidingrequest.jpg", created_at: "2013-08-14 01:54:27", updated_at: "2013-08-15 16:47:39">]>
the thing trying link multiple pictures 1 customer. lets above 2 pictures belong 1 customer , there 2 rows because there 2 pictures.
how reference in table, lets have 1 customer , thats me "judy" both record should reference judy's id?
and in view, can draw both pictures out using image tag belong customer id 1 - name = "judy" or customer id = 1?
if not making things clear please let me know, not familiar tables relationships , relationship me most.
create table :projects |t| t.references :clients t.timestamps end
create_table :pictures |t| t.string :name, null:false t.string :location, null:false t.references :projects, null:false t.timestamps end
... meanwhile.. in model layer class project < activerecord::model has_many :pictures, :dependent => destroy end
class picture < activerecord::model belongs_to :project validates_presence_of :project end
to judy's pictures
client.where("name ?", "judy").projects.first.pictures
Comments
Post a Comment