私はそのようなdbスキーマを持っています:
Tables:
COUNTRY_DESIGNATIONS
DES_TEXTS
MANUFACTURERS
MODELS
そしてそのような関係:
COUNTRY_DESIGNATIONS has_many MODELS
DES_TEXTS has_many COUNTRY_DESIGNATIONS
MANUFACTURERS has_many MODELS
Railsモデルでは、すべての関係とその他の「もの」が書かれています。
メーカーを選択すると、すべてのモデルが表示されます。しかし今、私はこれらのモデルで COUNTRY_DESIGNATIONS からデータを選択し (すべてのテーブル関係 ID が等しいことを確認してください)、次に COUNTRY_DESIGNATIONS からデータを選択するときに、DES_TEXTS からデータをフェッチして表示したいと考えています。
これどうやってするの?コントローラー、ビューの変更点は? (私は標準的な足場を使用していました)
今、私はメーカーからモデルを表示するためのそのようなビューを持っています:
- @manufacturer.models.each do |model|
%tr
%p
mod_id
%td= model.MOD_ID
%p
MOD_PCON_START
%td= model.MOD_PCON_START
%p
MOD_PCON_END
%td= model.MOD_PCON_END
= link_to 'Show model', model
そして、私はこのようなものを追加したい:
- @manufacturer.models.each do |model|
%tr
%p
...
%td= model.country_des.des_text.FIELD - something like this)
= link_to 'Show model', model
モデル ファイル:
class CountryDesignation < ActiveRecord::Base
set_table_name "COUNTRY_DESIGNATIONS"
set_primary_key :CDS_ID
belongs_to :des_text
belongs_to :language
has_many :models
end
class DesText < ActiveRecord::Base
set_table_name "DES_TEXTS"
set_primary_key :TEX_ID
has_many :country_designation
has_many :designation
end
class Model < ActiveRecord::Base
set_table_name "MODELS"
set_primary_key :MOD_ID
belongs_to :manufacturer
belongs_to :country_designation
has_many :types
end
dump:
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120418164608) do
create_table "COUNTRY_DESIGNATIONS", :primary_key => "CDS_ID", :force => true do |t|
t.binary "CDS_CTM"
t.integer "CDS_LNG_ID"
t.integer "CDS_TEX_ID"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "DESIGNATIONS", :primary_key => "DES_ID", :force => true do |t|
t.integer "DES_LNG_ID"
t.integer "DES_TEX_ID"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "DES_TEXTS", :primary_key => "TEX_ID", :force => true do |t|
t.text "TEX_TEXT"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "LANGUAGES", :primary_key => "LNG_ID", :force => true do |t|
t.integer "LNG_DES_ID"
t.string "LNG_ISO2"
t.string "LNG_CODEPAGE"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "MANUFACTURERS", :primary_key => "MFA_ID", :force => true do |t|
t.integer "MFA_PC_MFC"
t.integer "MFA_CV_MFC"
t.integer "MFA_AXL_MFC"
t.integer "MFA_ENG_MFC"
t.integer "MFA_ENG_TYP"
t.string "MFA_MFC_CODE"
t.string "MFA_BRAND"
t.integer "MFA_MF_NR"
t.binary "MFA_PC_CTM"
t.binary "MFA_CV_CTM"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "MODELS", :primary_key => "MOD_ID", :force => true do |t|
t.integer "MOD_MFA_ID"
t.integer "MOD_CDS_ID"
t.integer "MOD_PCON_START"
t.integer "MOD_PCON_END"
t.integer "MOD_PC"
t.integer "MOD_CV"
t.integer "MOD_AXL"
t.binary "MOD_PC_CTM"
t.binary "MOD_CV_CTM"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "TYPES", :primary_key => "TYP_ID", :force => true do |t|
t.integer "TYP_CDS_ID"
t.integer "TYP_MMT_CDS_ID"
t.integer "TYP_MOD_ID"
t.binary "TYP_CTM"
t.binary "TYP_LA_CTM"
t.integer "TYP_SORT"
t.integer "TYP_PCON_START"
t.integer "TYP_PCON_END"
t.integer "TYP_KW_FROM"
t.integer "TYP_KW_UPTO"
t.integer "TYP_HP_FROM"
t.integer "TYP_HP_UPTO"
t.integer "TYP_CCM"
t.integer "TYP_CYLINDERS"
t.integer "TYP_DOORS"
t.integer "TYP_TANK"
t.integer "TYP_KV_VOLTAGE_DES_ID"
t.integer "TYP_KV_ABS_DES_ID"
t.integer "TYP_KV_ASR_DES_ID"
t.integer "TYP_KV_ENGINE_DES_ID"
t.integer "TYP_KV_BRAKE_TYPE_DES_ID"
t.integer "TYP_KV_BRAKE_SYST_DES_ID"
t.integer "TYP_KV_FUEL_DES_ID"
t.integer "TYP_KV_CATALYST_DES_ID"
t.integer "TYP_KV_BODY_DES_ID"
t.integer "TYP_KV_STEERING_DES_ID"
t.integer "TYP_KV_STEERING_SIDE_DES_ID"
t.float "TYP_MAX_WEIGHT"
t.integer "TYP_KV_MODEL_DES_ID"
t.integer "TYP_KV_AXLE_DES_ID"
t.integer "TYP_CCM_TAX"
t.float "TYP_LITRES"
t.integer "TYP_KV_DRIVE_DES_ID"
t.integer "TYP_KV_TRANS_DES_ID"
t.integer "TYP_KV_FUEL_SUPPLY_DES_ID"
t.integer "TYP_VALVES"
t.integer "TYP_RT_EXISTS"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "carts", :force => true do |t|
t.integer "customer_id"
t.integer "item_id"
t.integer "amount"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "credit_cards", :force => true do |t|
t.integer "customer_id"
t.string "number"
t.string "nameOfCard"
t.date "expiryDate"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "currencies", :force => true do |t|
t.float "currencyvalue"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "customer_sessions", :force => true do |t|
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "customers", :force => true do |t|
t.string "username"
t.string "crypted_password"
t.string "password_salt"
t.string "persistence_token"
t.string "email"
t.string "skype"
t.integer "ICQ"
t.string "firstname"
t.string "lastname"
t.string "country"
t.string "state"
t.string "city"
t.string "street"
t.string "building"
t.integer "room"
t.string "addressNote"
t.string "dateOfReg"
t.integer "custGroup_id"
t.float "totalBuy"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "order_statuses", :force => true do |t|
t.string "statusname"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "orders", :force => true do |t|
t.integer "basket_id"
t.integer "customer_id"
t.integer "shipping_id"
t.integer "paymentmethod_id"
t.integer "orderstatus_id"
t.datetime "dateoforder"
t.float "totalcost"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "payment_methods", :force => true do |t|
t.string "methodname"
t.boolean "allowed"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "sellers", :force => true do |t|
t.string "username"
t.string "crypted_password"
t.string "password_salt"
t.string "persistence_token"
t.string "email"
t.string "skype"
t.integer "ICQ"
t.string "firstname"
t.string "lastname"
t.string "dateOfReg"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "shippings", :force => true do |t|
t.string "shippingname"
t.float "shippingcost"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "telephone_operators", :force => true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "telephones", :force => true do |t|
t.integer "customer_id"
t.integer "operator"
t.integer "number"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "virtual_pay_systems", :force => true do |t|
t.string "name"
t.boolean "active"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "virtual_pays", :force => true do |t|
t.integer "customer_id"
t.string "number"
t.integer "virtualpaysystem_id"
t.datetime "created_at"
t.datetime "updated_at"
end
end