Questions tagged [before-save]

An ActiveRecord callback that is executed after validating an object but before writing it to the database.

before_save is one of the standard ActiveRecord callbacks. There are three sets of callbacks:

  • Creating an Object (in order of execution):
    1. before_validation
    2. after_validation
    3. before_save
    4. around_save
    5. before_create
    6. around_create
    7. after_create
    8. after_save
  • Updating an Object (in order of execution):
    1. before_validation
    2. after_validation
    3. before_save
    4. around_save
    5. before_update
    6. around_update
    7. after_update
    8. after_save
  • Destroying an Object (in order of execution):
    1. before_destroy
    2. around_destroy
    3. after_destroy
154 questions
1
vote
2 answers

Yii2 beforeSave

I have a Controller and an updateAction generated with giiant: public function actionUpdate($id) { $model = $this->findModel($id); if ($model->load($_POST) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); …
user2511599
  • 736
  • 12
  • 36
1
vote
1 answer

How to have VBA select a button on a userform within another workbook?

So I am creating thousands of workbooks using a VBA from a Master Workbook. I have a template the Vba pastes to. This template workbook has a VBA BeforeSave function where the user has to fill out a Userform to log changes the user decided to make…
Kenny
  • 313
  • 1
  • 7
  • 23
1
vote
1 answer

How to have a VBA cancel the script?

How can I have the VBA code cancel if the cancel button is pressed. I have... Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) Dim ws As Worksheet Set ws = Sheets("EDITS") Dim tbl As ListObject Set tbl =…
Kenny
  • 313
  • 1
  • 7
  • 23
1
vote
2 answers

How are callbacks called?

What is the environment of a callback? For example, in listing 6.20 of the standard Ruby on Rails Tutorial" (http://rails-4-0.railstutorial.org/book/modeling_users) it has: class User < ActiveRecord::Base before_save { self.email = email.downcase…
Brian Postow
  • 10,227
  • 14
  • 69
  • 113
1
vote
1 answer

how to get data from before beforeSave()

In my system, I want a facility that it should always copy old record into another table before the actual table gets an update. So that admin can see new data and old data as well ( to maintain a record of old and new values) for that i use…
Paritosh Mahale
  • 923
  • 2
  • 8
  • 32
1
vote
1 answer

SaveAs inside BeforeSave (Excel, VBA)

I want to program Excel to create back-up of my file before saving it. But each time I am trying to use it, Excel crashes. Can please some explain me why this happens even if I insert Application.EnableEvents = False to prevent infinite loop? The…
1
vote
1 answer

Rails 5 - how to negate a method call on a before_save callback conditional

In my Template model I have this callback: before_save :set_status, if: :is_template? private def is_template? return self.template_type == 'template' end How can I change it so that it only fires when the template_type is NOT…
rmcsharry
  • 4,357
  • 4
  • 50
  • 87
1
vote
2 answers

Rails: before_save - Stack level too deep

I have this simple model: class Post < ApplicationRecord after_create_commit :process before_save :re_process, on: :update has_one :processed, class_name: 'Post::Process' def process self.processed.destroy if…
jonhue
  • 1,085
  • 1
  • 15
  • 47
1
vote
1 answer

Mongoid Rails - Is there a way to check the field's datatype before saving?

I have this class ProfitLoss which consists of these fields. I want to call this method zero_if_blank on before_validation as before_save is not working and what i want to do is assign 0 to those values which are blank and are of Integer when coming…
Rishabh
  • 75
  • 1
  • 8
1
vote
1 answer

Before save does not work with save as

I have made a macro that protects the sheet and changes sheet to sheet "A", then saves the file and after that comes back to the sheet I have started in. Unfortunately, the Save as option does not work when my macro is in the workbook. Whenever I…
Kuba
  • 231
  • 1
  • 4
  • 12
1
vote
0 answers

VBA excel : Forcing filename with Workbook_BeforeSave and ActiveWorkbook.SaveAs

I am building a form that is placed in a shared folder on a private network. The 'mother form', used by a single user, is a template that generates 'child forms' when it is saved using the information from the spreadsheet. To name my 'child forms',…
Shawna Baker
  • 25
  • 1
  • 4
1
vote
2 answers

CakePHP 3 - Use saved data inside afterSave()

I have submitted a form in my view which will be processed in the controller. What normally happens is that the controller saves the edits by doing this: if ($this->Requests->save($request)) { // the request have been saved. } Now I created…
S. Kerdel
  • 90
  • 1
  • 9
1
vote
2 answers

Parse.com Cloud Code beforeSave( ) Error: "Uncaught Tried to save an object with a pointer to a new, unsaved object"

In ACL of an object 'Hotel' i am trying to save id of 'Parse.User' object. I am saving ACL in beforeSave(). While saving object it gives me an error as "Uncaught Tried to save an object with a pointer to a new, unsaved object" Which i am unable to…
1
vote
5 answers

How to query objects in the CloudCode beforeSave?

I'm trying to compare a new object with the original using CloudCode beforeSave function. I need to compare a field sent in the update with the existing value. The problem is that I can't fetch the object correctly. When I run the query I always get…
1
vote
0 answers

Parse beforeSave not triggering

I'm saving an object called 'Post' and I have a field called 'author' which is a Pointer to the Parse.User class. When I create a new 'Post' object, I pass the 'author' value as the Parse.User.id value to my Cloud Code function. Obviously, this…
Cam Tullos
  • 2,310
  • 1
  • 18
  • 16
1 2
3
10 11