manage bookmarks, bugfixes
[smr.git] / gui / app / models / portfolio.rb
blob193abe5d0d17d29473bb6b2c102221d4faf603cc
2 # This file is part of SMR.
4 # SMR is free software: you can redistribute it and/or modify it under the
5 # terms of the GNU General Public License as published by the Free Software
6 # Foundation, either version 3 of the License, or (at your option) any later
7 # version.
9 # SMR is distributed in the hope that it will be useful, but WITHOUT ANY
10 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License along with
14 # SMR.  If not, see <http://www.gnu.org/licenses/>.
16 class Portfolio < ActiveRecord::Base
17     include Smr::Extensions::Link
18     include Smr::Extensions::DateTimeWrapper
19     include Smr::Extensions::BookmarkTools
21         belongs_to :User,        :foreign_key=>:id_user
22         has_many :Position,      :foreign_key=>:id_portfolio
23         has_many :DocumentAssign
24     has_many :Bookmark,      :foreign_key=>:id_portfolio
26     accepts_nested_attributes_for :Bookmark
28     # Scope like class method to select open positions of :id_user.
29     def self.with_open_positions(id_user)
30         where(:id_user=>id_user)
31         .joins(:Position).where(:position=>{:date_closed=>0}).group(:id)
32     end
34     def to_s
35         name
36     end
37 end