Snippets

The ASCI Extend Model in Existing Class

Updated by Austin

File Steps.markdown Modified

  • Ignore whitespace
  • Hide word diff
     * If this is not the case, the getters and setters need to be updated to reference the appropirate column variables. (e.g. `$this->poNumber` would need to become `$this->po_number` when the db column is named `po_number`.
         * My suggestion would be to keep all of the getters and setters, at least at this point. This will maintain compatability with existing code. I also personally like the getters and setters.    
     * The next thing I did was run the tests. This caught variables in the FactoryMuffin object that were mis-named. (e.g. `PaymentTransaction` factory used `invoiceId` and needed to be changed to `invoice_id`. This is more than just in the FactoryMuffin definition, because there was some custom construction of these factories in various test suites.)
-4. I elimitated code that would set improper data to an empty string in order to have it remain `null`. (e.g. `check_deposit_date` was set to a date if it was valid, else ''. I removed the else and chose to ignore any assignment. It simply stays `null`.
-5. Look through CRUD methods implemented in the class (e.g. `save()`, `delete()`, etc). Remove them.
+4. Remove any default constructors (including constructors where all parameters have default values assigned.
+    * This will break lots of stuff. In tests, I would recommend taking the constructor and substituting it for a Factory object with the parameters set via FactoryMuffin.
+5. I elimitated code that would set improper data to an empty string in order to have it remain `null`. (e.g. `check_deposit_date` was set to a date if it was valid, else ''. I removed the else and chose to ignore any assignment. It simply stays `null`.
+6. Look through CRUD methods implemented in the class (e.g. `save()`, `delete()`, etc). Remove them.
     * `PaymentTransaction::save()` was a little more complicated than a simple update of attributes in the database. It also called upon invoice to update its balance.
     * `PaymentTransaction::save()` also set the `created` attribute. I originally put a hook to set `created` after create, but that overwrote things set in the Factory. Plus there is a default value in the database, so it should be good to leave out.
 
Updated by Austin

File Steps.markdown Modified

  • Ignore whitespace
  • Hide word diff
 -----
 
 1. Change `class PaymentTransaction` to `class PaymentTransaction extends Model`
-    * Running tests after results in a SQL Error about the table `manuscripticon_test.payment_transactions` does not exist
-        * 
+    * Running tests after results in a SQL Error about the table `manuscripticon_test.payment_transactions` does not exist.
+        * Add `static $table_name = "<sql table name>"` to class.
 2. Remove any private class variables associated with db columns (e.g. `$created`).
 3. For `PaymentTransaction` many of the class variables were named with underscores in the way they are in the databases. 
     * If this is not the case, the getters and setters need to be updated to reference the appropirate column variables. (e.g. `$this->poNumber` would need to become `$this->po_number` when the db column is named `po_number`.
Updated by Austin

File Steps.markdown Modified

  • Ignore whitespace
  • Hide word diff
 -----
 
 1. Change `class PaymentTransaction` to `class PaymentTransaction extends Model`
+    * Running tests after results in a SQL Error about the table `manuscripticon_test.payment_transactions` does not exist
+        * 
 2. Remove any private class variables associated with db columns (e.g. `$created`).
 3. For `PaymentTransaction` many of the class variables were named with underscores in the way they are in the databases. 
     * If this is not the case, the getters and setters need to be updated to reference the appropirate column variables. (e.g. `$this->poNumber` would need to become `$this->po_number` when the db column is named `po_number`.
Updated by Austin

File Steps.markdown Modified

  • Ignore whitespace
  • Hide word diff
     * If this is not the case, the getters and setters need to be updated to reference the appropirate column variables. (e.g. `$this->poNumber` would need to become `$this->po_number` when the db column is named `po_number`.
         * My suggestion would be to keep all of the getters and setters, at least at this point. This will maintain compatability with existing code. I also personally like the getters and setters.    
     * The next thing I did was run the tests. This caught variables in the FactoryMuffin object that were mis-named. (e.g. `PaymentTransaction` factory used `invoiceId` and needed to be changed to `invoice_id`. This is more than just in the FactoryMuffin definition, because there was some custom construction of these factories in various test suites.)
-4. I elimitated code that would set improper data to an empty string in order to have it remain `null`. (e.g. `check_deposit_date` was set to a date if it was valid, else ''. I removed the else and chose to ignore any assignment. It simply stays null.
+4. I elimitated code that would set improper data to an empty string in order to have it remain `null`. (e.g. `check_deposit_date` was set to a date if it was valid, else ''. I removed the else and chose to ignore any assignment. It simply stays `null`.
 5. Look through CRUD methods implemented in the class (e.g. `save()`, `delete()`, etc). Remove them.
     * `PaymentTransaction::save()` was a little more complicated than a simple update of attributes in the database. It also called upon invoice to update its balance.
     * `PaymentTransaction::save()` also set the `created` attribute. I originally put a hook to set `created` after create, but that overwrote things set in the Factory. Plus there is a default value in the database, so it should be good to leave out.
Updated by Austin

File Steps.markdown Modified

  • Ignore whitespace
  • Hide word diff
     * If this is not the case, the getters and setters need to be updated to reference the appropirate column variables. (e.g. `$this->poNumber` would need to become `$this->po_number` when the db column is named `po_number`.
         * My suggestion would be to keep all of the getters and setters, at least at this point. This will maintain compatability with existing code. I also personally like the getters and setters.    
     * The next thing I did was run the tests. This caught variables in the FactoryMuffin object that were mis-named. (e.g. `PaymentTransaction` factory used `invoiceId` and needed to be changed to `invoice_id`. This is more than just in the FactoryMuffin definition, because there was some custom construction of these factories in various test suites.)
-4. Look through CRUD methods implemented in the class (e.g. `save()`, `delete()`, etc). Remove them.
+4. I elimitated code that would set improper data to an empty string in order to have it remain `null`. (e.g. `check_deposit_date` was set to a date if it was valid, else ''. I removed the else and chose to ignore any assignment. It simply stays null.
+5. Look through CRUD methods implemented in the class (e.g. `save()`, `delete()`, etc). Remove them.
     * `PaymentTransaction::save()` was a little more complicated than a simple update of attributes in the database. It also called upon invoice to update its balance.
     * `PaymentTransaction::save()` also set the `created` attribute. I originally put a hook to set `created` after create, but that overwrote things set in the Factory. Plus there is a default value in the database, so it should be good to leave out.
 
  1. 1
  2. 2
  3. 3
  4. 4
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.