Here's is an array with 5 elements 2.1.2 :001 > arr = ["a", "b", "c", "d", "e"] => ["a", "b", "c", "d", "e"] Lets look at few different cases Insert a new element at starting position Using unshift 2.1.2 :002 > arr.unshift("f") => ["f", "a", "b", "c", "d", "e"] Using insert 2.1.2 :005 > arr.insert(0, "f") => ["f", "a", "b", "c", "d", "e"] In the above example 0 is the position(index) Move existing element from one position to another The element in this case is "e" Using uniq to show only unique elements 2.1.2 :009 > arr.insert(0, "e").uniq => ["e", "a", "b", "c", "d"] With uniq we are only showing unique records but the element is listed
There are multiple ways to implement one-to-many relationship in ServiceNow Reference Fields GlideList Document ID fields ServiceNow has provided "Document ID" field to hold a reference of any table because at some times we have a requirement to hold the reference irrespective of the table. Document ID lets the user choose the table and the associated record
Validations allow you to ensure that only valid data is stored in your database. Example: validates_presence_of :user_name, :password validates_numericality_of :value We can write custom validation also as def validate errors.add(:price, “should be a positive value”) if price.nil?|| price < 0.01 end Callbacks and observers allow you to trigger logic before or after an alteration of an object’s state. Callbacks are methods that get called at certain moments of an object’s life cycle. With callbacks it’s possible to write code that will run whenever an Active Record object is created, saved, updated, deleted, validated, or loaded from the database. Callbacks are hooks into the life cycle of an Active Record object that allow you to trigger logic before or after an alteration of the object state. This can be used to make sure that associated and dependent objects are deleted when destroy is called (by overwriting before_destroy) or to massage attribu
Comments
Post a Comment