A blog wouldn't really be a blog if users can't make comments to a post. We are going to now add comments to our posts by relating a post to a comment object.
1. First thing to do is to create a comment persistent object. Let's create a template called
Comment.cfc
with the following description:<cfcomponent persistent="true" entityname="comment" output="false"> <cfproperty name="id" ormtype="id" generator="native"> <cfproperty name="from" ormtype="string"> <cfproperty name="comment" ormtype="text"> <cfproperty name="dateCreated" fieldtype="timestamp"> <cfproperty name="post" fieldtype="one-to-one" fkcolumn="id" cfc="Post" insert="false" update="false"> </cfcomponent>
We have seen most of the properties before, except that now a
Comment
has a property calledpost
that is related to thePost
object.First, we add a
fieldtype="one-to-one"
to the property to define how this component will relate in the ORM to thePost...