Results 1 to 3 of 3

Thread: How to relate two modules?

  1. #1
    johan69 is offline Junior Member
    Join Date
    Aug 2009
    Posts
    1

    Default How to relate two modules?

    Hello,

    I have created 2 custom modules, one keeps a list of items A, and the other keeps a list of items B. For every item A, there can be 0-* items B. I have a field/dbcolumn with the same name ("C") in both module A and B to connect them. If an item A and an item B have the same data in a certain column, I want them to be automatically related. For example, if an invoice record have the same invoice number as some invoice_item records, then they are automatically connected such that one invoice<->some invoice_items.

    I have created a 1:N relationship in Sugar, such that module A is connected to module B using the "C" field/dbcolumn.

    This works well in the sense that I can create a number of items A, and a number of Items B. If I create items B from within the detail view of an item A, this item A will also list all such item B's in a subpanel.
    So in this case, such item B's are connected to the item A, and a relation exist between them. Fine.

    But if I create a number of Item B's, from the B module view, these will not be listed in an item A subpanel, even if the column "C" contain the correct key.

    So in short, how can I create a module A and B, there all item B's will be listed automatically in an item A's subpanel, if the data in a field/dbcolumn "C" is the same in both A and B?

    Any suggestions is most welcome!

    Kind regards,
    Johan

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

    Default Re: How to relate two modules?

    I'd suggest using some sort of logic hook like after_save. In it compare and find any records that have a similar value and then manually add the relationship. It is possible to do but it'll take some elbow grease.

  3. #3
    jleaman's Avatar
    jleaman is offline Senior Member
    Join Date
    May 2009
    Location
    Boston
    Posts
    58

    Default Re: How to relate two modules?

    johan, were you able to get this working?

    I would love to be able to set a relationship using a logic hook but I reached a dead-end in both ideas I could come up with to solve this:

    1) I either need two write both id's to the relationship table. Easy enough except the relationship item has it's own unique ID so I would have to set this ID. How does sugar generate unique ID's? Can I generate one myself if one does not exist yet? This seems like the more difficult path.

    2) Call the relationship information with a $bean-> reference. This is also challenging as the relationship information is not stored in the module's primary table. It is possible to load other modules into 'bean aliases' but neither the parent's or child's table reference the relationship. Can Sugar's beans be used to get and set relationship information?

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. HOWTO: Hack - Relate to custom modules pre 5.1
    By kenneth.thorman in forum Developer Tutorials
    Replies: 4
    Last Post: 2011-02-07, 06:42 AM
  2. How to relate newly created modules
    By k.divya in forum Developer Help
    Replies: 2
    Last Post: 2009-03-19, 04:01 AM
  3. How can I relate emails to new Modules?
    By j.lagos in forum Developer Help
    Replies: 2
    Last Post: 2008-12-19, 12:06 PM
  4. Does relate feild contains custom modules
    By Mubi in forum Developer Help
    Replies: 2
    Last Post: 2008-07-03, 12:03 PM
  5. relate two modules
    By sacramentojoe in forum Help
    Replies: 10
    Last Post: 2008-01-11, 12:59 AM

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
  •