【问题标题】:how to get parents id while fetching child's information - Grails?如何在获取孩子的信息时获取父母的身份 - Grails?
【发布时间】:2013-06-13 03:45:04
【问题描述】:

如何访问用户的名字和姓氏,具体取决于显示的 statusItem 是用户的孩子。

class UserAccount implements Serializable {


static transients = ['pass','passConfirm','familyPicTmp', 'familyPicTmpFilename', 'photoTmp', 'photoTmpFilename']
static hasMany = [authorities: Authorisation, memberships:FamilyMembership, progenitorIwi:Family,  politicItems:PoliticItem,
    relationships:Relationship, , agents:UserAccount, media:UserMedia, status:Status]
static mappedBy = [ progenitorIwi:"progenitor",relationships:'relationTo', relationships:'userAccount']
static fetchMode = [memberships:FetchMode.JOIN, agents:FetchMode.JOIN]
static mapping = {
    memberships(lazy:false)
    agents(lazy:false)
}

static belongsTo = [Authorisation]

状态域

class Status {
  static belongsTo = [userAccount:UserAccount]
  def String statusMessage
  Date dateCreated
  Date lastUpdated
  def String statusType

政治领域

class PoliticItem {

    SystemEntity politicItemName
    UserAccount userAccount

    def String politicItemValue
    def boolean shared = false
    Date dateCreated
    Date lastUpdated

我们如何将属于所有状态的所有用户加载到政治视图中?

【问题讨论】:

  • 你能澄清你的问题吗?可能您需要发布您的相关域。
  • 请检查我对所有域的更新问题...@Alidad
  • 您对问题的澄清越多,在这里可以帮助您的人就越多。我不太明白你在找什么。您是否试图根据用户的状态来查找用户?如果是这样,状态域中的 userAccount 是对父级的反向引用。
  • 我不知道该怎么做..你能告诉我语法吗..谢谢
  • 不,当我尝试将所有状态的列表直接加载到状态视图时,它会加载一切正常的图像,但不会显示图像并且在政治档案中我只是不知道如何根据状态加载用户信息。

标签: grails controller


【解决方案1】:

我仍然不确定你不知道哪一部分。假设 userAccount 有 firstName 和 lastName 字段可以从状态访问它们,试试这个:

status 是您的 Status 类的实例。您需要从中获取 userAccount 的那个。

status.userAccount.firstName

status.userAccount.lastName

【讨论】:

  • 这里有大量帮助...您认为是否存在任何类型的限制或任何限制图像显示的内容,即使显示正确的图像 url...@Alidad
  • 您可能需要为该图像打开另一个问题,并提供更多相关信息。
  • 我使用动态查找器和您提供的语法解决了它...谢谢@Alidad
猜你喜欢
  • 2021-03-12
  • 1970-01-01
  • 2021-11-09
  • 1970-01-01
  • 2013-06-04
  • 2022-11-24
  • 2015-08-30
  • 2013-04-10
  • 2018-01-29
相关资源
最近更新 更多