One of the strengths of SugarCRM is that any record can be very easily related to another one. The platform supports one-to-one, one-to-many, and many-to-many relationships, giving you plenty of flexibility is designing your application.
In this blog post, we’ll see how thru code we can get a list of all of the related records to a particular record. This example will deal with grabbing related contacts to an account. Let’s take a look at the code
They key method here is get_linked_beans(), which takes two default arguments. The first is the name of the link field that represents the relationship; you can find this info out in the vardefs.php file for the module. The second argument is the name of the bean you’ll be creating for each found related record. So in this instance, we’ll be looking over the ‘contacts’ link field for the relationship to use, and for each found record we’ll create a Contact bean record. The return value is an array of beans ( in this case, Contact beans ). We iterate over the beans and output the name of the contact.