I have 2 tables. Table 1 and table 2/table 1 model and table 2 model. One of my columns in table 1 is : order, in my table 2, i want to call the order column in my table 1 to set a default value before it saves.
Question: How can I get the order column from table 2?
table 2/table 2 model
class Itinerary < ApplicationRecord
belongs_to :user, foreign_key: :created_by
belongs_to :activity
before_save :default_value, :count_all_activity
after_save
# has_many :activity_itineraries, foreign_key: :created_by
has_many :activity_itineraries, inverse_of: :itinerary
has_many :activities, through: :activity_itineraries
validates :user, presence: true
validates :title, presence: true, length: { maximum: 20 }
validates :no_of_days, presence: true,
:numericality => true
private
def default_value
self.order = "1"
end
def count_all_activity
end
end
Aucun commentaire:
Enregistrer un commentaire