The object tag is used to define an object. Attributes on the tag and sets of child tags define details about reactor generated objects. For example you can use an alias tag on the object to rename an object from something like "tbl_Cust_Markets" to "CustomerMarket". You can use the field tag to do the same thing for fields. The hasOne and hasMany tags are used to define relationships between objects.
Ultimately the settings defined via the object tag control most of Reactor's functionality.
The name attribute is used to specify either a table or view in your database.
To create instances of an object you are not required to specify an object tag. If you had a table in your database called "tbl_Cust_Markets" you can, without specifying an object tag, instantiate objects based on the table. For example (assuming the ReactorFactory has already been instantiated):
<cfset CustomerMarketRecord = ReactorFactory.createRecord("tbl_Cust_Markets") />
The resulting objects will be written under the project directory and the mapping directory with names like "tbl_Cust_MarketsRecord.cfc". This may be adequate for your needs, but it's not really elegant. A better option would be to define the object using an object tag and to give it an alias. For example:
<object name="tbl_Cust_Markets" alias="CustomerMarket" />
Note: The alias is singular because each of a common convention in Reactor. For example, one record represents one row in the database. It doesn't really make sense to have a UsersRecord. A UserRecord makes more sense.
<cfset CustomerMarketRecord = ReactorFactory.createRecord("CustomerMarket") />
Note: Throughout the framework methods which require you to specify objects actually only accept object aliases. In the case that you don't provide an object alias Reactor simply sets the alias to the name.
|
Attribute |
Required |
Description |
|---|---|---|
|
name |
Yes |
This is the name of the object as defined in your database. This may or may not be case sensitive, depending on your DBMS. An object may be a table or a view. If an alias is not provided then the name attribute will define the name of objects as they are written to disk and as they are |
|
alias |
No |
This is an alias by which you will address this object. The alias will be used to name objects on disk and to instantiate instances of reactor generated objects for this object.
If this attribute is not provided it is defaulted to the value of the name attribute. |
|
Tag |
Required |
Description |
|---|---|---|
|
field |
No |
I define alias for a field and sequences for fields on DBMS that require them. |
|
hasOne |
No |
I define a relationship where this object has one of another object. For example, a user may have one address. |
|
hasMany |
No |
I define a relationship where this object has many of another object. For example, an address may have many users. |
<reactor>
<objects>
<object
name="User">
<hasOne
name="Address">
<relate
from="addressId" to="addressId" />
</hasOne>
</objects>
<object
name="Address">
<hasMany
name="User">
<relate
from="addressId" to="addressId" />
</hasMany>
</objects>
</objects>
</reactor>