save not working - debug_query shows 'SHOW COLUMNS FROM' instead of insert query

edited October 2015 in Modules
I am using version 1.2 in a local MAMP PRO setup. Ajax call from a view is...
var dataArr = { affiliatesArr: Lockr.get("affIDs"), course_id: "<?=$course_id?>", transaction_id: "<?=$transaction->id?>" } $.ajax({ url: "/transactions/ajax_affiliate_credit", type: "post", data: dataArr, success: function(data) { console.log("SUCCESS! "); console.log(data); }, error: function(data) { console.log("ERROR: "); console.log(data); } });
fuel/application/controllers/transactions.php is...
<?php class Transactions extends CI_Controller { function __construct() { parent::__construct(); } function ajax_affiliate_credit() { if($this->input->is_ajax_request()) { $affiliateCredits = $this->input->post(); $this->load->model('transactions_model'); $result = $this->transactions_model->store_affiliate_credits($affiliateCredits); } else { return null; } } }
the store_affiliate_credits method in /fuel/application/models/transactions_model.php is...
function store_affiliate_credits($affiliateCredits) { $CI =& get_instance(); $CI->load->model('affiliate_sale_credits_model'); $affiliates = $affiliateCredits['affiliatesArr']; $course_id = $affiliateCredits['course_id']; $transaction_id = $affiliateCredits['transaction_id']; foreach($affiliates as $affiliate) { $affiliateData = array('transaction_id' => $transaction_id, 'affiliate_id' => $affiliate['id']); $CI->affiliate_sale_credits_model->save($affiliateData); $CI->affiliate_sale_credits_model->debug_query(); } return $affiliateCredits; }
The console.log is returning this...

SUCCESS! SHOW COLUMNS FROM `affiliate_sale_credits`
and of course nothing is being inserted into the db. I'm using XDebug in Sublime Text and, when I set a breakpoint in the transactions model at the end of the store_affiliate_credits() method, all the variables are filled with good values.

My db table is this...
CREATE TABLE `affiliate_sale_credits` ( `id` int(11) NOT NULL, `transaction_id` int(11) NOT NULL, `affiliate_id` int(11) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Indexes for dumped tables -- -- -- Indexes for table `affiliate_sale_credits` -- ALTER TABLE `affiliate_sale_credits` ADD PRIMARY KEY (`id`), ADD KEY `transaction_id` (`transaction_id`), ADD KEY `affiliate_id` (`affiliate_id`); -- -- AUTO_INCREMENT for dumped tables -- -- -- AUTO_INCREMENT for table `affiliate_sale_credits` -- ALTER TABLE `affiliate_sale_credits` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

Any idea what I might be doing wrong?

Comments

  • access rights for the table?
  • edited 10:47PM
    Access rights are set properly. One thing I left out is /fuel/application/models/affiliate_sale_credits_model.php ...
    <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); require_once(FUEL_PATH.'models/base_module_model.php'); class Affiliate_sale_credits_model extends Base_module_model { public $foreign_keys = array( 'transaction_id' => 'transactions_model' ); function __construct() { // $this->load->module_model(USER_FOLDER,'site_users_model'); parent::__construct('affiliate_sale_credits'); //table } }
    Other info:
    * I'm using ion auth - there is a 'user' advanced module
  • edited October 2015
    What puzzles me is why does...
    $CI->affiliate_sale_credits_model->save($affiliateData);
    Followed by...
    $CI->affiliate_sale_credits_model->debug_query();
    Result in...
    SHOW COLUMNS FROM `affiliate_sale_credits`

    I've looked at php and mySQL logs and see no errors.
  • edited 10:47PM
    Are there any errors upon save?
    print_r($CI->affiliate_sale_credits_model->get_errors());
  • edited October 2015
    Thanks so much for that tip! Didn't remember get_errors(). That uncovered the issue. I had carelessly saved the affiliate_id as an integer in the table. Should've been a varchar. Also the transaction_id was typed as a string in the method...

    Array ( [transaction_id] => Value needs to be a number for 'transaction id'. [affiliate_id] => Value exceeds required length for 'affiliate id'. ) SHOW COLUMNS FROM `affiliate_sale_credits`
    Thanks again. It's now working.
Sign In or Register to comment.