trouble with self refrencing relationship

View: New views
3 Messages — Rating Filter:   Alert me  

trouble with self refrencing relationship

by davekojo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I am new to grails and am trying to allow my user to follow a user or become a friend of a user. I am currently getting the error:

org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: User.addToFollowing() is applicable for argument types: (java.lang.String) values: [ronald]

I have setup my domain class like this

class User {
    static searchable = true
   
    String userId
    String password
    boolean enabled = true
     
    // For Spring Security plugin's user registration.
    String email
    String userRealName
    boolean emailShow

    Date dateCreated
    Profile profile

    static hasMany = [
            posts : Post,
            tags : Tag,
            following : User,
            authorities : Role ]
    static belongsTo = Role

And the am trying to implement the friendship with this in my controller.

    def addFollower = {
        def user = params.id ? User.findByUserId(params.id) : User.get(authenticateService.userDomain().id)

        def other = User.findByUserId(params.otherId)

        user.addToFollowing(params.otherId)
                     
redirect (controller: "post", action: "timeline")
}
}

I believe the code is taking the logged in user, the user who you would like to become friends with and the adding them to the following relationship.


Re: trouble with self refrencing relationship

by Eyck Jentzsch :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

davekojo schrieb:

> I am new to grails and am trying to allow my user to follow a user or become
> a friend of a user. I am currently getting the error:
>
> org.codehaus.groovy.runtime.InvokerInvocationException:
> groovy.lang.MissingMethodException: No signature of method:
> User.addToFollowing() is applicable for argument types: (java.lang.String)
> values: [ronald]
>
> I have setup my domain class like this
>
> class User {
>     static searchable = true
>    
>     String userId
>     String password
>     boolean enabled = true
>      
>     // For Spring Security plugin's user registration.
>     String email
>     String userRealName
>     boolean emailShow
>
>     Date dateCreated
>     Profile profile
>
>     static hasMany = [
>             posts : Post,
>             tags : Tag,
>             following : User,
>             authorities : Role ]
>     static belongsTo = Role
>
> And the am trying to implement the friendship with this in my controller.
>
>     def addFollower = {
>         def user = params.id ? User.findByUserId(params.id) :
> User.get(authenticateService.userDomain().id)
>
>         def other = User.findByUserId(params.otherId)
>
>         user.addToFollowing(params.otherId)
>                      
> redirect (controller: "post", action: "timeline")
> }
> }
>
> I believe the code is taking the logged in user, the user who you would like
> to become friends with and the adding them to the following relationship.
>
>
Hi,
params.otherId is just a string, you need to use the User object:
   user.addToFollowing(other)
I guess its a typo...
-Eyck


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: trouble with self refrencing relationship

by davekojo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks very much

Eyck Jentzsch wrote:
davekojo schrieb:
> I am new to grails and am trying to allow my user to follow a user or become
> a friend of a user. I am currently getting the error:
>
> org.codehaus.groovy.runtime.InvokerInvocationException:
> groovy.lang.MissingMethodException: No signature of method:
> User.addToFollowing() is applicable for argument types: (java.lang.String)
> values: [ronald]
>
> I have setup my domain class like this
>
> class User {
>     static searchable = true
>    
>     String userId
>     String password
>     boolean enabled = true
>      
>     // For Spring Security plugin's user registration.
>     String email
>     String userRealName
>     boolean emailShow
>
>     Date dateCreated
>     Profile profile
>
>     static hasMany = [
>             posts : Post,
>             tags : Tag,
>             following : User,
>             authorities : Role ]
>     static belongsTo = Role
>
> And the am trying to implement the friendship with this in my controller.
>
>     def addFollower = {
>         def user = params.id ? User.findByUserId(params.id) :
> User.get(authenticateService.userDomain().id)
>
>         def other = User.findByUserId(params.otherId)
>
>         user.addToFollowing(params.otherId)
>                      
> redirect (controller: "post", action: "timeline")
> }
> }
>
> I believe the code is taking the logged in user, the user who you would like
> to become friends with and the adding them to the following relationship.
>
>
Hi,
params.otherId is just a string, you need to use the User object:
   user.addToFollowing(other)
I guess its a typo...
-Eyck


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email