Snippets
Revised by
Austin
be79966
I'm going to use PaymentTransaction as the example as I work through the conversion. This way I can note tips and tricks to save some future headache.
Steps
- Change
class PaymentTransaction
toclass PaymentTransaction extends Model
- Remove any private class variables associated with db columns (e.g.
$created
). - 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 namedpo_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 usedinvoiceId
and needed to be changed toinvoice_id
. This is more than just in the FactoryMuffin definition, because there was some custom construction of these factories in various test suites.)
- If this is not the case, the getters and setters need to be updated to reference the appropirate column variables. (e.g.
- 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 thecreated
attribute. I originally put a hook to setcreated
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.
Notes
Test Failures
- Many test failures will be resolved easily by remaning properties etc.
- I had test failues due to date issues.
PaymentTransaction::check_deposit_date
was being saved as adate
whilePaymentTransaction::created
wasdatetime
. The switch to ActiveRecord caused some weirdness in the Reporter that had an if/else query on those two fields. The factory was creating a date fromcreated
while expecting it to be a string. Simply setting it as a Date object resolved this issue.
You can clone a snippet to your computer for local editing. Learn more.