Skip navigation.
can program OOP!

MG:Unity - Calling your own custom reactor gateway methods using a Generic list

| |

Are you guys using the ModelGlue generic list? A basic generic list (using reactor as the orm) calls the getByFields() method in the reactor gateway for the object you specify.

for example, if you broadcast this message in your eventhandler:

<message name="modelglue.genericList">
<argument name="object" value="user" />
<argument name="criteria" value="userID" />
</message>

Would call getByFields(UserID={userIDValueInTheViewState})

and stuff the results into the viewstate.



Well, If you need complex query results (joins etc), you can specify the gateway method to call and modelglue will pass on the criteria as arguments to your custom method.

<message name="modelglue.genericList">
<argument name="object" value="user" />
<argument name="criteria" value="userID" />
<argument name="gatewayMethod" value="getUserInfo" />
</message>

Then ModelGlue will take the results and stuff them into the viewstate just like any other generic list.



Reactor.xml: Understanding the difference between 'relate' and 'link'

|

One of my favorite features of reactor (besides everything) is the ability to set up hasOne and HasMany relationships in your reactor.xml file and then be able to use iterators and get other related records and data from the record you are working with. setting up these relationship seems to be an area of confusion for people as they get started with reactor.

Relationships:

There are two basic relationship types: hasOne and HasMany to decide from. this should be an easy task if you already have a basic plan for the app. It may help if you imagine yourself as the object...I am a user object and I 'have many' roles or I am a user and I 'have one' address.

Relationship Types:

Inside the hasOne or hasMany tag, you can define the relationship type.

There are two basic types of reactor.xml relationship types, Reactor syntax calls these 'relate' and 'link'
This is HOW the objects are related. Either a direct relationship(relate) or through a linking table (link)

relate

This is when the Primary key(PK) of one table is used as a foreign key in a second table. This is the one to use if you are only involving 2 tables -with no linking table in the middle. In the below example the 'UserID' PK in the User table is a foreign key in the Reports table. In this instance the user 'Has Many' Reports using a relate tag:

<object name="User" >
    <hasMany name="Report">
        <relate from="UserID" to="UserID" />
    </hasMany>
</object>

this is the easiet to set up in reactor as you just need only define the two objects with a tag within the hasOne or hasMany

link

the 'link' syntax is for when you have a table in the middle like in the case of a user table, a role table and a table that links userID's to RoleID's (UserRole table) This requires three reactor object definitions. in this example: User, Role and UserRole
the user and role both 'have many' of each other:

<object name="User">
    <hasMany name="Role">
        <link name="UserRole" />
    </hasMany>
</object>
<object name="Role">
    <hasMany name="User">
        <link name="UserRole" />
    </hasMany>
</object>

The linking table (UserRole) has 2 hasOne definitions, relating back to the 2 PK's

<object name="UserRole">
    <hasOne name="User">
        <relate from="UserID" to="UserID" />
    </hasOne>
    <hasOne name="Role">
        <relate from="RoleID" to="RoleID" />
    </hasOne>
</object>

I hate negative fieldnames

|

Just had to dive into an un-named co-worker's code to look at an issue. Please never name your boolean fieldnames in the negative, I may have to interprit your code and I have no patience for these antics!

here is the scenario:

there is a negativly named field in the DB named boo_nonsmoker.

here is the Radio Button code block

<input type="radio" name="boo_flex_nonsmoker_NewValue1" value="F" <cfif not BooleanIsTrue(qryEmployee.boo_flex_nonsmoker)>checked</cfif>>
“I certify that I am a non-smoker.”
<br>
<input type="radio" name="boo_flex_nonsmoker_NewValue1" value="T" <cfif BooleanIsTrue(qryEmployee.boo_flex_nonsmoker)>checked</cfif>>I and/or my spouse is a smoker.

So in this scenario if they smoke, boo_nonsmoker gets set to true, making it really a flag for smokers, not nonsmokers.....it gets even more confusing when setting the default value...cfif not BooleanIsTrue nonsmoker.

oh, if only the field had just been named smoker instead.....