SugarCRM Relationships 101

I’m going through the Relationships 101 tutorial for SugarCRM.

First Comment:

Why keep database metadata in code?  It’s better in SQL, but if you’re going to get away from the source, why not something better, like YAML?  Better still to discover and cache, but something like this:

table: cases_opportunities
    - fields:
        - name: id
          type: varchar
          len: 36
          ...

is easier to understand and more concise than SugarCRM’s metadata file:

$dictionary['cases_opportunities'] = array (
    'table' => 'cases_opportunities',
    'fields' => array (
        array('name' => 'id', 'type' => 'varchar', 'len' => '36'),
        ...

You could then use Spyc to slurp it up.  But of course, PHP’s shared nothing state and non-compilation would make that tricky.  You’d end up checking timestamps on files and that’s no way to run a real server.

Even more, the file is a standard format, and everything can be deduced from the two table names (and public key names, which should always be ‘id’ by convention.)

So a helper function that takes the two table names (‘cases’ and ‘opportunities’) could be used to generate all the needed metadata.  I realize that there might be a need to overwrite this, but hashes of hashes isn’t the solution.  PHP4 has enough OOP capability and reflection to be able to do this.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s