PageRenderTime 65ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/wheels/tests/model/associations/belongsTo.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 45 lines | 38 code | 7 blank | 0 comment | 0 complexity | 702655153d68eb9dc5acf4acb9285c6e MD5 | raw file
Possible License(s): Apache-2.0, CPL-1.0
  1. <cfcomponent extends="wheelsMapping.Test">
  2. <cffunction name="test_getting_parent">
  3. <cfset loc.obj = model("post").findOne(order="id")>
  4. <cfset loc.dynamicResult = loc.obj.author()>
  5. <cfset loc.coreResult = model("author").findByKey(loc.obj.authorId)>
  6. <cfset assert("loc.dynamicResult.key() IS loc.coreResult.key()")>
  7. <cfset loc.dynamicResult = loc.obj.author(select="lastName", returnAs="query")>
  8. <cfset loc.coreResult = model("author").findByKey(key=loc.obj.authorId, select="lastName", returnAs="query")>
  9. <cfset assert("IsQuery(loc.dynamicResult) AND ListLen(loc.dynamicResult.columnList) IS 1 AND IsQuery(loc.coreResult) AND ListLen(loc.coreResult.columnList) IS 1 AND loc.dynamicResult.lastName IS loc.coreResult.lastName")>
  10. </cffunction>
  11. <cffunction name="test_checking_if_parent_exists">
  12. <cfset loc.obj = model("post").findOne(order="id")>
  13. <cfset loc.dynamicResult = loc.obj.hasAuthor()>
  14. <cfset loc.coreResult = model("author").exists(loc.obj.authorId)>
  15. <cfset assert("loc.dynamicResult IS loc.coreResult")>
  16. </cffunction>
  17. <cffunction name="test_getting_parent_on_new_object">
  18. <cfset loc.authorByFind = model("author").findOne(order="id")>
  19. <cfset loc.newPost = model("post").new(authorId=loc.authorByFind.id)>
  20. <cfset loc.authorByAssociation = loc.newPost.author()>
  21. <cfset assert("loc.authorByFind.key() IS loc.authorByAssociation.key()")>
  22. </cffunction>
  23. <cffunction name="test_checking_if_parent_exists_on_new_object">
  24. <cfset loc.authorByFind = model("author").findOne(order="id")>
  25. <cfset loc.newPost = model("post").new(authorId=loc.authorByFind.id)>
  26. <cfset loc.authorExistsByAssociation = loc.newPost.hasAuthor()>
  27. <cfset assert("loc.authorExistsByAssociation IS true")>
  28. </cffunction>
  29. <cffunction name="test_getting_parent_on_combined_key_model">
  30. <cfset loc.combikey = model("combikey").findOne()>
  31. <cfset loc.user = loc.combikey.user()>
  32. <cfset assert("IsObject(loc.user)")>
  33. </cffunction>
  34. <cffunction name="test_getting_parent_with_join_key">
  35. <cfset loc.obj = model("author").findOne(order="id", include="user")>
  36. <cfset assert('loc.obj.firstName eq loc.obj.user.firstName')>
  37. </cffunction>
  38. </cfcomponent>