Multi-tenancy rails application issues
thattimc opened this issue · 1 comments
thattimc commented
Hi, we are building out a multi-tenancy web app which requires adding the account_id field on read_mark table. We would love to use unread gem and is it possible to allow us for insert the custom field via code?
ledermann commented
First, add the account_id
field to the ReadMark
table:
class AddAccountIdToReadMarks < ActiveRecord::Migration[5.1]
def change
add_column :read_marks, :account_id, :integer
end
end
The, add an initializer to your app and include your custom code like this:
class ReadMark
belongs_to :account
before_save do |read_mark|
read_mark.account_id ||= read_mark.reader.account_id # or get the account_id from elsewhere...
end
end