MorningPeak/app/models/user.rb
Arthur Poulet 7646e982d3 fix comment, implementation
- creator polymorphic instead of user
- implementation
2015-07-25 22:30:19 +02:00

27 lines
699 B
Ruby

class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable,
#:registerable,
:recoverable,
:rememberable,
:trackable#,
#:validatable
has_one :client
delegate :name, to: :client
has_many :tickets, as: :creator
has_many :comments, as: :creator
has_many :contacts, through: :client
has_many :bills, through: :client
after_create :create_client
def create_client
update(client: Client.create(name: email.gsub(/@.+/, '')))
end
def tickets_unview
tickets.heads.where(head_creator_view_at: nil)
end
end