27
Feb

ORM Property Formula

This is pretty cool and pretty easy as long as you have all your relationships properly set up. You can include a formula inside a property that will allow you to easily get the results. The catch is you will need to write it in SQL and not HQL. You could also write this as a tranditional funcion and get the same result.

property name="publishedPostCount" setter="false" default="0" formula="SELECT count(p.post_id) FROM post AS p WHERE userID = p.fk_userID AND p.IS_PUBLISHED = 1";

When it comes time to display the data all you would have to do is call getPublishedPostCount()

Tags: Railo; ORM; Coldfusion