app/models/dc_piece.rb in drg_cms-0.4.39 vs app/models/dc_piece.rb in drg_cms-0.4.53
- old
+ new
@@ -18,11 +18,19 @@
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++
-class DcPiece
+
+
+#########################################################################
+# ActiveSupport::Concern definition for DcPiece class.
+#########################################################################
+module DcPieceConcern
+ extend ActiveSupport::Concern
+ included do
+
include Mongoid::Document
include Mongoid::Timestamps
field :name, type: String, default: ''
field :description, type: String, default: ''
@@ -42,16 +50,36 @@
field :valid_to, type: DateTime
field :created_by, type: BSON::ObjectId
field :updated_by, type: BSON::ObjectId
+ validates :name, presence: true
+end
+end
+
+########################################################################
+# Mongoid::Document model for dc_piece documents.
+#
+# DcPiece model is used for documents or pieces of web site which are common to site
+# or perhaps to all sites in database. For example page footer is a good candidate
+# to be saved in a dc_piece collection.
+#
+# Documents in dc_pieces collection must have unique name assigned. Default DcPartRenderer
+# also looks into dc_pieces collection and collects all documents which belong to
+# current site (site_id field) and renders them according to div_id field value.
+########################################################################
+class DcPiece
+ include DcPieceConcern
+
index( { name: 1 }, { unique: true } )
- index( { site_id: 1 } )
+ index( { site_id: 1 } )
+ validates :name, uniqueness: true
+
########################################################################
-# Return choices for select for dc_policy_role_id
+# Return choices for select for selecting documents on dc_part form.
########################################################################
def self.choices4_pieces
all.inject([]) { |r,piece| r << [ piece.name, piece._id] }
end
-end
+end
\ No newline at end of file