findAll vs list problem

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

findAll vs list problem

Owen Rubel
I have a simple domain that looks like the following:

##########

class Post {
   
    static hasMany = [comments:Comment, topics:PostTopics]
    static belongsTo = [User]
                                         
    String title
    String teaser
    String content
    Date creationDate = new Date()
    Date modifiedDate
    User author
    Status stat
    Section section
    SortedSet comments
   
   
    static constraints = {
        title(size:1..50, nullable:false, blank:false)
        teaser(size:1..255, nullable:false, blank:false)
        content(size:0..65536, nullable:true)
        author(nullable:false)
        stat(nullable:true)
        section(nullable:false)
    }

}

#########

Now when I call it via the controller, using the following function, it works great...

    def listPost = {
        def post = Post.list(sort:'modifiedDate',order:'desc')
        render(view:'listPost',model:[posts:post])
    }

But if I try to list the posts by topic, I get an error saying it can't see 'section'. The following is the method used...

    def listPostByTopic = {
        def topic = Topic.get(params.id)
        def post = Post.findAll( "from Post P left join P.topics PT where PT.topic=?",[topic]);
        render(view:'listPost',model:[posts:post])
    }

Anyone have a clue why this is happening?? I'm baffled.



Reply | Threaded
Open this post in threaded view
|

Re: findAll vs list problem


Now this code doesn't cause an error with listPost but when i use listPostByTopic, it causes an error when it hits  'post.section.getSectionName()'
Owen Rubel
Oh for the record, the code that is causing the error is in the view...

${post.section.getSectionName()} : ${post.title}
Reply | Threaded
Open this post in threaded view
|

Re: findAll vs list problem

Gene Golovchinsky
Have you tried executeQuery() rather than findAll() ? Does that produce the same behavior?
Reply | Threaded
Open this post in threaded view
|

Re: findAll vs list problem

Owen Rubel
Yep. Tried that and got no records returned.

Which makes no sense to me as my id is being returned.

On Fri, Jan 29, 2010 at 10:17 AM, Gene Golovchinsky [via Grails] <[hidden email]> wrote:
Have you tried executeQuery() rather than findAll() ? Does that produce the same behavior?


View message @ http://n4.nabble.com/findAll-vs-list-problem-tp1415712p1415793.html
To unsubscribe from Re: findAll vs list problem, click here.


Reply | Threaded
Open this post in threaded view
|

Re: findAll vs list problem

Owen Rubel
Here's the code I use that returns zero records

    def listPostByTopic = {
        def topic = Topic.get(params.id)
        def post = Post.executeQuery("select P.title,P.teaser,P.content,P.creationDate,P.modifiedDate,P.author,P.stat,P.section from Post P left join P.topics PT where PT.topic=?",[topic]);
        render(view:'listPost',model:[posts:post])
    }

Just to make sure that the topic is set, I even echo it out and it is returning a List so I know that's set.

On Fri, Jan 29, 2010 at 10:22 AM, owen Rubel <[hidden email]> wrote:
Yep. Tried that and got no records returned.

Which makes no sense to me as my id is being returned.

On Fri, Jan 29, 2010 at 10:17 AM, Gene Golovchinsky [via Grails] <[hidden email]> wrote:
Have you tried executeQuery() rather than findAll() ? Does that produce the same behavior?



View this message in context: Re: findAll vs list problem

Sent from the Grails - user mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

Re: findAll vs list problem

Gene Golovchinsky
In reply to this post by Owen Rubel
One more thought: when you do executeQuery() do you keep the same query expression? Have you tried

Post.executeQuery("select P from Post ...." )

Gene
Reply | Threaded
Open this post in threaded view
|

Re: findAll vs list problem

Owen Rubel
Therein was my problem. I was declaring all the columns to return instead.

That works great. Thanks for the help. :)