Saturday, June 11, 2016

Using the bean instead of SQL all the time

select * from accounts where name = 'Foo Bar';

$focus = new Account();
$focus->retrieve_by_string_fields(array('name' => 'Foo Bar' ));

$focus = new Account();
$focus->retrieve('my record id');



select * from contacts where id in ( select contact_id from accounts_contacts where account_id = 'my record id' )

$focus = new Account();
$focus->retrieve('my record id');
$focus->load_relationship('contacts');

$list = array();
foreach ($focus->contacts->getBeans() as $contact) {
    $list[$contact->id] = $contact;
}




update accounts set name = 'Bar Foo' where id = 'my record id'

$focus = new Account();
$focus->retrieve('my record id');
$focus->name = 'Bar Foo';
$focus->save();



insert into accounts_contacts (id, contact_id, account_id, date_modified, deleted) values ...

$focus = new Account();
$focus->retrieve('my account id');
$focus->load_relationship('contacts');
$focus->contacts->add('my contact id');
$focus->save();



delete from accounts_contacts where contact_id = 'my contact id' and account_id = 'my account id'

$focus = new Account();
$focus->retrieve('my account id');
$focus->load_relationship('contacts');
$focus->contacts->delete($focus->id, 'my contact id');
$focus->save();




1 comment:

  1. Hi All!

    I'm selling fresh & genuine SSN Leads, with good connectivity. All data properly checked & verified.
    Headers in Leads:

    First Name | Last Name | SSN | Dob | Address | State | City | Zip | Phone Number | Account Number | Bank Name | DL Number | Routing Number | IP Address | Reference | Email | Rental/Owner |

    *You can ask for sample before any deal
    *Each lead will be cost $1
    *Premium Lead will be cost $5
    *If anyone wants in bulk I will negotiate
    *Sampling is just for serious buyers

    Hope for the long term deal
    For detailed information please contact me on:

    Whatsapp > +923172721122
    Email > leads.sellers1212@gmail.com
    Telegram > @leadsupplier
    ICQ > 752822040

    ReplyDelete