Results 1 to 5 of 5

Thread: Identifying Unique Account for Each Contact

  1. #1
    kbocek is offline Junior Member
    Join Date
    Jun 2007
    Posts
    3

    Default Identifying Unique Account for Each Contact

    Using SugarOS 4.5.1d on linux

    I'm needing to write some custom queries in ZuckerReports and need to understand how Sugar relates the various tables. I'd like to know how Sugar identifies the Account Name that is associated with each contact. I understand that the accounts_contacts table provides the "glue" between accounts and contacts. However Sugar allows multiple entries in this table for a contact.

    How do you specify the employer or 'primary' account for a contact?

    Thanks,
    Kirk Bocek

  2. #2
    dpatech is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    NC
    Posts
    287

    Default Re: Identifying Unique Account for Each Contact

    Sugar allows multiple contacts to be related to a single account, but only one account per contact. Therefore, given any single contact, you can use the accounts_contacts table to find the account. There is nothing in this table that indicates which is the primary contact for the account.
    - Sugar Team
    dpa Technology LLC
    e-mail: dpaDeveloper@dpatechnology.com
    web: http://www.dpatechnology.com

  3. #3
    kuske's Avatar
    kuske is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    Germany
    Posts
    2,597

    Default Re: Identifying Unique Account for Each Contact

    Do not forget to look only to records of accounts_contacts with column deleted = 0.

    When you change the account of a contact (e.g. at merging of accounts) records with deleted = 1 can stay in database table accounts_contacts.

  4. #4
    eggsurplus's Avatar
    eggsurplus is offline Sugar Community Member
    Join Date
    Dec 2005
    Location
    Minnesota
    Posts
    2,343

    Default Re: Identifying Unique Account for Each Contact

    On the contacts screen the account name that you see is the first record returned from accounts_contacts. So you can select top 1 or limit 1,1 if you need just the account that is displayed on the screen.

  5. #5
    kbocek is offline Junior Member
    Join Date
    Jun 2007
    Posts
    3

    Default Re: Identifying Unique Account for Each Contact

    Thank you eggsurplus, that was the information I was looking for. I thought it might be something like that but wanted confirmation. Something along the lines of
    Code:
    select * from accounts_contacts where contact_id='xxx' and 
       deleted=0 order by id asc limit 1
    should give me what I want.
    Last edited by kbocek; 2007-11-29 at 03:30 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Contact and Account address
    By People3 in forum Help
    Replies: 6
    Last Post: 2008-11-26, 06:39 PM
  2. Replies: 3
    Last Post: 2007-12-05, 06:18 PM
  3. Associating Bug Contact with Account
    By Softwise in forum Help
    Replies: 3
    Last Post: 2007-10-15, 03:41 PM
  4. Import contact on existing account
    By esolarc in forum Developer Help
    Replies: 1
    Last Post: 2006-03-22, 01:21 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •