SQL で数秒かかる基本的な結合を実行しようとしていますが、ORMExecuteQuery (Hibernate ベースの Coldfusion 9) で動作させようとしています。
私は3つのオブジェクトを持っています: - Contact - ContactCategory_Link - ContactCategory
コンポーネントの詳細は、機能しているものと機能していないものの簡単な説明の後に続きます。
基本的に、連絡先には多くのカテゴリを含めることができ、カテゴリにも多くの連絡先を含めることができます。リンクごとに異なるパラメータを追加する必要があるため (たとえば、連絡先ごとにカテゴリを並べ替えたい (エンドユーザーはカテゴリを並べ替えることができる必要があります) と、システムに必要なその他の情報)。この種の追加情報を追加することはできないように思われるため、多対多の関係は使用しませんでした。
したがって、完全に機能するリクエストは次のとおりです。
<cfset response["rows"] = ORMExecuteQuery("
SELECT new map(c.name as Name)
FROM Contact c
")>
連絡先の名前を完全に指定します。ただし、別のテーブルを追加しようとするたびに失敗します。例えば:
<cfset response["rows"] = ORMExecuteQuery("
SELECT new map(c.name as Name)
FROM Contact c
JOIN ContactCategory_Link
")>
あげる:
Path expected for join!
ContactCategory_Link
に変更している場合でも、ContactCategory_Link.contact
次のような結果が得られます。
Invalid path: 'null.contact'
したがって、コンポーネントの CFC が正しく設定されていないと推測していますが、その理由はわかりません。
この件について私を助けてくれませんか?
各オブジェクトのコードは次のとおりです。
<cfcomponent displayname="Contact" entityname="Contact" table="step8_contact" persistent="true" output="false">
<cfproperty name="id" column="contactID" type="guid" fieldtype="id" setter="false" unique="true" notnull="true" generated="insert" generator="identity">
<cfproperty name="name" column="name" type="string" length="125" required="true">
<cfproperty name="categories" fieldtype="one-to-many" singularname="category" fkcolumn="contactID" cfc="ContactCategory_Link" missingRowIgnored="true" cascade="all-delete-orphan">
</cfcomponent>
<cfcomponent displayname="ContactCategory_Link" entityname="ContactCategory_Link" table="step8_contactcategory_link" persistent="true" output="false">
<cfproperty name="id" column="contactcategory_linkID" type="numeric" fieldtype="id" setter="false" unique="true" notnull="true" generated="insert" generator="identity">
<cfproperty name="orderId" column="orderId" type="numeric" required="true"> <!---notnull="true"--->
<cfproperty name="contact" fieldtype="many-to-one" fkcolumn="contactID" cfc="Contact" missingRowIgnored="true">
<cfproperty name="contactcategory" fieldtype="many-to-one" fkcolumn="contactcategoryID" cfc="ContactCategory" missingRowIgnored="true">
</cfcomponent>
<cfcomponent displayname="ContactCategory" output="false" persistent="true" entityname="ContactCategory" table="step8_contactcategories" hint="" cacheuse="read-only" cachename="contactcategory">
<cfproperty name="id" column="contactcategoryID" type="numeric" fieldtype="id" setter="false" unique="true" notnull="true" generated="insert" generator="identity">
<cfproperty name="label" column="label" type="string" length="255" required="true" notnull="true">
<cfproperty name="orderId" column="orderId" type="numeric" required="true" notnull="true">
<cfproperty name="categories" fieldtype="one-to-many" singularname="category" fkcolumn="contactcategoryID" cfc="ContactCategory_Link" missingRowIgnored="true" cascade="all-delete-orphan" lazy="true">
</cfcomponent>
ご協力いただきありがとうございます。