First attempt at custom logic in on_after_save function b/w 2 Advanced Modules

edited May 2012 in Modules
I have 2 model files that are each contained in separate advanced module directories. The first one is an "invoices" model and the second is a "check_receipts" model. The goal is when creating a check receipt, a form field to store the invoice number will trigger the invoice with that number in the invoices model to update its status field to "paid".

I want to use the on_after_save function to update the invoice to paid when a check receipt is saved with the invoice number that matches an invoice in the database. Since they are in separate advanced module directories, I'm running into trouble figuring out how I would relate these two models together. In the form_fields method of the example articles_model it loads in the authors, categories and categories_to_articles models using:

$CI =& get_instance(); $CI->load->model('authors_model');

I get an error when trying to load the invoices model from the check_receipts model because the invoices_model.php is located in a different spot than where the check_receipts model file resides.

Is there an additional argument I can pass to the $CI->load->model() function call to designate where to look for it?

Erik

Comments

  • edited May 2012
    I got the 404 error to go away by switching the load->model function to
    // Load Invoices Model $CI->load->module_model(CORPORATE_PARTNERS_FOLDER, 'invoices_model' );

    An additional question at this point then is:

    Does the proper functioning of the $this->save_related() function depend on loading in the module's model file in the form_fields() method? I assume so since nowhere else in the example articles_model.php file does it appear to me that the connection to the 'categories_to_articles_model' is defined.

    Erik
  • edited 5:24AM
    Perhaps I'm misunderstanding, but it shouldn't depend on what is loaded in the form_fields method. The "categories_to_articles_model" should be the first parameter passed to the method. More can be found here if you haven't seen this page of the documentation:
    http://getfuelcms.com/user_guide/libraries/my_model/table_class_functions
Sign In or Register to comment.