I am working with Grails and MongoDB. I have two domain classes User and AddWebsite. A User hasMany websites and each website belongs to a user. The domain classes are as follows:
class AddWebsite{
String website
User user
static belongsTo = [user: User]
static constraints = {
website url:true
user nullable:true
}
}
The Other domain class is as follows:
class User {
String login
String password
static hasMany = [
addWebsites: AddWebsite
]
static mapping = {
addWebsites cascade:"all-delete-orphan"
}
static constraints = {
}
}
I need to query the AddWebsite table based on the current logged in user and get the websites of that particular user. Can anyone suggest any approach?
I used this approach. May not be most efficient but it works .
def showWebsites(){
def p = User.findByLogin(session["user"].login)
def websites = AddWebsite.findAllByUser(p['_id'])
[websitesList: websites]
}
And in my GSP I have:
<g:select name="websiteSelection" from="${websitesList.website} " />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With