Counting Related Records in Javascript

Hi all.

I'm new to SugarCRM dev/javascript. Can anyone push me in the right direction for learning more about the model. I cannot find any pure docs on the model/controllers themselves, just examples of it being used (Which don't delve into more detail) and almost all of the articles I can find don't link into the new sugarclub.

What I want to do, is on Field Validation on a record, check the related records of Contacts from Opportunities and count them. And see if the number is greater than 0.

I have a brief understanding and can do something similar to this:

cont_id = this.model.get('contacts_cases_1contacts_ida');

       

        var ContactBean = SUGAR.App.data.createBean('Contacts', {id:cont_id}); 

        ContactBean.fetch({'success':function () { 

              designation = ContactBean.get('title'); 

              comp_type  = ContactBean.get('type_of_account_c');

           

              acc_id = ContactBean.get('account_id');

              acc_name = ContactBean.get('account_name');

            model.set('sup_desgn_c',designation);

            model.set('company_type_c',comp_type);

            model.set('account_id',acc_id);

            model.set('account_name',acc_name);

          

       }});

But if anyone can push me into more information on the model and how the information gets displayed that'd be fantastic. I have a good understanding of Bean and believe it's fairly similar.

Thank you,


Daniel