Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法解析属性:名称:bookmarks.TagReference-Grails,Search_Search_Grails_Tags_Bookmarks - Fatal编程技术网

无法解析属性:名称:bookmarks.TagReference-Grails,Search

无法解析属性:名称:bookmarks.TagReference-Grails,Search,search,grails,tags,bookmarks,Search,Grails,Tags,Bookmarks,晚上好,, 我正在根据格雷姆·罗彻的《圣杯权威指南》一书创建一个书签应用程序。在这个应用程序中,我有4个域:用户、书签、标记和标记引用。 书签 hasMany = [tags:TagReference] def belongsTo = User User user URL url String title String notes 标记引用 Bookmark bookmark User user Tag tag 标签 String name 我试着不仅按标题和注释搜索书签,还按标签

晚上好,, 我正在根据格雷姆·罗彻的《圣杯权威指南》一书创建一个书签应用程序。在这个应用程序中,我有4个域:用户、书签、标记和标记引用。 书签

hasMany = [tags:TagReference]
def belongsTo = User
User user   

URL url
String title
String notes
标记引用

Bookmark bookmark
User user
Tag tag
标签

String name
我试着不仅按标题和注释搜索书签,还按标签搜索书签

书签控制器:

def search = {
    def criteria = Bookmark.createCriteria()
    def b = criteria.list {
                or {
                    ilike('title',"%${params.q}%".toString())
                    ilike('notes',"%${params.q}%".toString())

                    tags {
                        ilike('name',"%${params.q}%".toString())}
                    }
            }

           def fromDelicious = null
           try {
               fromDelicious = deliciousService.findRecent(session.user)
           }
           catch(Exception e) {
               log.error('Failed to invoke del.icio.us: ' + e.message, e)
           }
        render(view:'list',model:[bookmarkInstanceList:b.unique(),deliciousResults:fromDelicious])
/布局/主要

<g:form controller="bookmark" action="search" >
<input type="text" name="q" /> <input type="submit" value="search" />

我理解这是因为我的TagReference没有属性名,但如何获取它?

鉴于您的域模型,您需要通过tags集合访问Tag.name属性。因此,您的标准将如下所示:

def criteria = Bookmark.createCriteria()
def b = criteria.list {
            or {
                ilike('title',"%${params.q}%".toString())
                ilike('notes',"%${params.q}%".toString())

                tags {
                    tag {
                        ilike('name',"%${params.q}%".toString())}
                    }
                }
        }
def criteria = Bookmark.createCriteria()
def b = criteria.list {
            or {
                ilike('title',"%${params.q}%".toString())
                ilike('notes',"%${params.q}%".toString())

                tags {
                    tag {
                        ilike('name',"%${params.q}%".toString())}
                    }
                }
        }