2017-05-03 22 views
0

現在のユーザーから特定のレンタルリストを取得しようとしています。コントローラでgrails - org.hibernate.QueryException(プロパティを解決できませんでした)

コード:

def index() { 
if (isLoggedIn()) { 
    String username = getPrincipal().username 

    def accountInstance = Account.findByUsername(username) 
    def rentalInstanceList = Rental.findAll("from Rental as r where r.account_id=:accountid", [accountid: accountInstance.id]) 
    } 
} 

ACCOUNT_IDが外部キーです。

実行した後、私はエラーを取得する:

could not resolve property: account_id of: ers.Rental 

は私が間違って何をしているのですか?

+0

レンタルドメインクラスを確認できますか? –

答えて

1

通常、HQLでは、ドメインクラスで定義されているフィールド名を使用する必要があります。 getPrincipal()の戻り値の型がidフィールドを持っている場合

def list = Rental.findAll("from Rental where accountId=:accountid", [accountid: accountInstance.id]) 

または

def list = Rental.findAllByAccount accountInstance 

あるいは

def list = Rental.findAllByAccount getPrincipal() 

:だから、あなたのクエリは次のようになります。

関連する問題