現在、私はデモ プロジェクトとして CRM アプリに取り組んでいます。現在、あるオブジェクトのプロパティに別のオブジェクトからアクセスする方法に頭を悩ませています。私は次の行に沿って何かをしようとしています:
<%= note.client.first_name %>
この場合、クライアントごとにメモを作成し、2 つのクライアント間に適切な関連付けを設定します。モデルは次のようになります。
class Note < ActiveRecord::Base
belongs_to :client
belongs_to :user
end
class Client < ActiveRecord::Base
has_many :users
has_many :notes
end
データベースは次のようになります。
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :first_name
t.string :last_name
t.string :designation
t.string :phone
t.string :email
t.string :password_digest
t.timestamps
end
end
end
メモに関連付けられたクライアント ID の :first_name プロパティにアクセスする簡単な方法はありますか?