From 47e3f87308d896bbe5ae136d864a185a11f63008 Mon Sep 17 00:00:00 2001 From: jasder Date: Wed, 3 Apr 2019 17:32:30 +0800 Subject: [PATCH] =?UTF-8?q?ADD=20=E6=B7=BB=E5=8A=A0=E5=85=B3=E8=81=94?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/customer.rb | 5 +++++ app/models/message.rb | 5 +++++ app/models/partner.rb | 5 +++++ app/models/school.rb | 3 +++ app/models/user.rb | 1 + db/migrate/20190403085155_create_partners.rb | 9 +++++++++ db/migrate/20190403085807_create_customers.rb | 10 ++++++++++ ...091639_add_partner_id_and_customer_id_to_schools.rb | 8 ++++++++ db/migrate/20190403092802_add_partner_id_to_users.rb | 6 ++++++ 9 files changed, 52 insertions(+) create mode 100644 app/models/customer.rb create mode 100644 app/models/partner.rb create mode 100644 db/migrate/20190403085155_create_partners.rb create mode 100644 db/migrate/20190403085807_create_customers.rb create mode 100644 db/migrate/20190403091639_add_partner_id_and_customer_id_to_schools.rb create mode 100644 db/migrate/20190403092802_add_partner_id_to_users.rb diff --git a/app/models/customer.rb b/app/models/customer.rb new file mode 100644 index 00000000..dab10ac9 --- /dev/null +++ b/app/models/customer.rb @@ -0,0 +1,5 @@ +class Customer < ActiveRecord::Base + belongs_to :partner + has_one :scholl + has_many :users +end diff --git a/app/models/message.rb b/app/models/message.rb index 6fb9bb59..63a7ce5f 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -53,6 +53,7 @@ class Message < ActiveRecord::Base has_many :tidings, :as => :container , :dependent => :destroy belongs_to :reply, :class_name => 'Message', :foreign_key => 'reply_id' + has_one :message_detail, :dependent => :destroy #转发表 has_many :forwards, :as => :from, :dependent => :destroy @@ -117,6 +118,10 @@ class Message < ActiveRecord::Base self.content end + def content + self.message_detail.try(:content) + end + def topic? parent_id.nil? end diff --git a/app/models/partner.rb b/app/models/partner.rb new file mode 100644 index 00000000..e838e464 --- /dev/null +++ b/app/models/partner.rb @@ -0,0 +1,5 @@ +class Partner < ActiveRecord::Base + attr_accessible :name + has_one :school + has_many :customers +end diff --git a/app/models/school.rb b/app/models/school.rb index 2a33acac..0cce7390 100644 --- a/app/models/school.rb +++ b/app/models/school.rb @@ -15,6 +15,9 @@ class School < ActiveRecord::Base has_many :ec_majors, :through => :ec_major_schools has_many :ec_major_schools, :dependent => :destroy + belongs_to :partner + belongs_to :customer + # banner图片信息 has_many :school_images, :dependent => :destroy diff --git a/app/models/user.rb b/app/models/user.rb index 31c58f26..752ea113 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -160,6 +160,7 @@ class User < Principal ## added by xianbo for delete # has_many :biding_projects, :dependent => :destroy belongs_to :softapplication, :foreign_key => 'id', :dependent => :destroy + belongs_to :partner ##ended by xianbo #####fq diff --git a/db/migrate/20190403085155_create_partners.rb b/db/migrate/20190403085155_create_partners.rb new file mode 100644 index 00000000..17516692 --- /dev/null +++ b/db/migrate/20190403085155_create_partners.rb @@ -0,0 +1,9 @@ +class CreatePartners < ActiveRecord::Migration + def change + create_table :partners do |t| + t.string :name + + t.timestamps + end + end +end diff --git a/db/migrate/20190403085807_create_customers.rb b/db/migrate/20190403085807_create_customers.rb new file mode 100644 index 00000000..51460758 --- /dev/null +++ b/db/migrate/20190403085807_create_customers.rb @@ -0,0 +1,10 @@ +class CreateCustomers < ActiveRecord::Migration + def change + create_table :customers do |t| + t.references :partner + + t.timestamps + end + add_index :customers, :partner_id + end +end diff --git a/db/migrate/20190403091639_add_partner_id_and_customer_id_to_schools.rb b/db/migrate/20190403091639_add_partner_id_and_customer_id_to_schools.rb new file mode 100644 index 00000000..1633f149 --- /dev/null +++ b/db/migrate/20190403091639_add_partner_id_and_customer_id_to_schools.rb @@ -0,0 +1,8 @@ +class AddPartnerIdAndCustomerIdToSchools < ActiveRecord::Migration + def change + add_column :schools, :partner_id, :integer + add_index :schools, :partner_id + add_column :schools, :customer_id, :integer + add_index :schools, :customer_id + end +end diff --git a/db/migrate/20190403092802_add_partner_id_to_users.rb b/db/migrate/20190403092802_add_partner_id_to_users.rb new file mode 100644 index 00000000..22a5d101 --- /dev/null +++ b/db/migrate/20190403092802_add_partner_id_to_users.rb @@ -0,0 +1,6 @@ +class AddPartnerIdToUsers < ActiveRecord::Migration + def change + add_column :users, :partner_id, :integer + add_index :users, :partner_id + end +end