asciisd / zoho

Zoho package for Laravel
36 stars 36 forks source link

Zohoable Model "SQLSTATE[42S02]: Base table or view not found" #11

Closed ibmgeniuz closed 3 years ago

ibmgeniuz commented 3 years ago

Hello, I have a Model called ZohoLead using the Zohoable Model. However, where I try to get data with it, I get the error below.

"message": "SQLSTATE[42S02]: Base table or view not found: 1146 Table 'table_name.zoho_leads' doesn't exist (SQL: select * from `zoho_leads` where `zoho_leads`.`id` = 1 limit 1)"

If you add protected $table = 'zohos', to the created model, it works but then it looks like ZohoLead::find(1) will give you the first item whether it is a lead or not.

The solution I find will be to add a global scope in the model to only search for items with type of ZohoLeads. .

Is there a better way of doing it? Or am I missing something?

Thanks

aemaddin commented 3 years ago

Hi @ibmgeniuz,

$table property is for Laravel database connection, so we didn't connect to the Laravel database when we get objects from Zoho, I am using method called searchCriteria

so you need to change $zoho_module_name not $table

protected $zoho_module_name = 'ZohoLead'; 

and you can see example for how to write search criteria as this ex:

public function searchCriteria(): string
    {
        return CriteriaBuilder::where('Transaction_ID', 3220)
                              ->orWhere('Order_ID', 3221)
                              ->toString();
    }
ibmgeniuz commented 3 years ago

@aemaddin

<?php

namespace App\Models;

use Asciisd\Zoho\Zohoable;
use Asciisd\Zoho\CriteriaBuilder;

class ZohoLead extends Zohoable
{
    // this is your Zoho module API Name
    protected $zoho_module_name = 'Leads';
    protected $table = 'zohos';

    /**
     * This used when we need to search for your current model record on zoho
     *
     * @return String|CriteriaBuilder
     */
    public function searchCriteria()
    {
        // TODO: Implement searchCriteria() method.
    }

    /**
     * Array for mandatory fields that required to create new record
     *
     * @return array
     */
    public function zohoMandatoryFields()
    {
        return [];
    }
}

This is my model. When I take out the protected $table = 'zohos'; , I get the error.

I just tried changing it to ZohoLead, but that will mean there's a module called ZohoLead, however, there's no such module on Zoho.

ibmgeniuz commented 3 years ago

@aemaddin It also tells me Column 'zohoable_id' cannot be null when I try to use $leads->createOrUpdateZohoId($id); . Will there be any reason this is the case? Is that autogenerated or there is a way to set zohoable_id for each model. Thank you once again.

PS. I can move this question to another issue, if that will help to track this.

aemaddin commented 3 years ago

ok please move it to another issue if that's ok.

thanks

ibmgeniuz commented 3 years ago

ok please move it to another issue if that's ok.

thanks

I have done. Please fine it below below #issue-785996876

Thank you.

aemaddin commented 3 years ago

please remove

protected $table = 'zohos'; // so that will override on package database location
ibmgeniuz commented 3 years ago

Thank you @aemaddin . That fixed it. Also to add, I had to create the database table zoho_leads in case I needed to use any functions such as ZohoLead::find(1) and use it against the Zohoable model functions. As demonstrated here 12#issuecomment