SugarCRM6.5数据查询方法研究

作者:James Zhu ([email protected])

创建日期:2018-09-05

单条数据查询

  1. 根据accounts.id查询数据

    // Method 1
    $account = BeanFactory::getBean('Accounts', $account_id);
    // Method 2
    $account = BeanFactory::getBean('Accounts');
    $account->retrieve($account_id);
    
  2. 根据属性字段accounts.name查询数据

    $account = BeanFactory::getBean('Accounts');
    $account->retrieve_by_string_fields(array('name' => $account_name));
    

列表数据查询

  1. 分页数据列表

    $account_list = BeanFactory::getBean('Accounts')->get_list('', 'accounts.name like \'%Inc%\'');
    

    返回数据示例:

    Array
    (
        [list] => Array
            (
                [0] => Account Object
                [1] => Account Object
                ...
            )
        [row_count] => 8
        [next_offset] => 20
        [previous_offset] => -20
        [current_offset] => 0
    )
    
  2. 所有数据列表

    $account_list = BeanFactory::getBean('Accounts')->get_full_list('', 'accounts.name like \'%Inc%\'');
    

    返回数据示例:

    Array
    (
        [0] => Account Object
        [1] => Account Object
        ...
    )
    

关联数据查询

$account = BeanFactory::getBean('Accounts', $account_id);
if($account->load_relationship('contacts')) {
    // Method 1
    $contacts = $account->contacts->getBeans();
    // Method 2
    $contacts = $account->contacts->beans;
}

results matching ""

    No results matching ""