<commit_before>Feature: Relationship queries
  In order to perform more advanced queries than allowed by GORM
  As a developer
  I want to query relationships using scopes
  
  Scenario: Query for children
    Given I have the following domain class:
      """
      class MarriedPerson {
        String name
        String gender
        MarriedPerson spouse
        Integer age
        
        static constraints = {
          gender(nullable: true)
          spouse(nullable: true)
        }
      }
      """
    And I have created the following "MarriedPerson" graph:
      """
        [
          {
            "name": "Harold",
            "gender": "male",
            "age": 18,
            "spouse": {
              "class": "MarriedPerson",
              "name": "Maude"
            }
          },
          {
            "name": "Maude",
            "gender": "female",
            "age": 57
          },
          {
            "name": "Jeff",
            "gender": "male",
            "age": 26,
            "spouse": {
              "class": "MarriedPerson",
              "name": "Nancy"
            }
          },
          {
            "name": "Nancy",
            "gender": "female",
            "age": 24,
            "spouse": {
              "class": "MarriedPerson",
              "name": "Jeff"
            }
          }
        ]
      """
    When I execute the following code:
      """
      MarriedPerson.where {
        spouse where: {
          age gte: 25
        }
      }.all()
      """
    Then I should get the following results:
      | name    |
      | Nancy   |
      | Harold  |
  
  Scenario: Query using a map
    Given I have the following domain class:
      """
      class FriendlyPerson {
        String name
        String gender
        FriendlyPerson bestFriend
        
        static constraints = {
          gender(nullable: true)
          bestFriend(nullable: true)
        }
      }
      """
    And I have created the following "FriendlyPerson" graph:
      """
        [
          {
            "name": "Harold",
            "gender": "male",
            "bestFriend": {
              "class": "FriendlyPerson",
              "name": "Maude"
            }
          },
          {
            "name": "Maude",
            "gender": "female"
          },
          {
            "name": "Jeff",
            "gender": "male",
            "bestFriend": {
              "class": "FriendlyPerson",
              "name": "Harold"
            }
          },
          {
            "name": "Nancy",
            "gender": "female",
            "bestFriend": {
              "class": "FriendlyPerson",
              "name": "Maude"
            }
          }
        ]
      """
    When I execute the following code:
      """
      FriendlyPerson.where {
        gender mapTo: "friend_gender"
        bestFriend where: {
          gender equals: mapping("friend_gender")
        }
      }.all()
      """
    Then I should get the following results:
      | name    |
      | Nancy   |
      | Harold  |<commit_msg>One of the relationship tests had the wrong expected results.<commit_after>Feature: Relationship queries
  In order to perform more advanced queries than allowed by GORM
  As a developer
  I want to query relationships using scopes
  
  Scenario: Query for children
    Given I have the following domain class:
      """
      class MarriedPerson {
        String name
        String gender
        MarriedPerson spouse
        Integer age
        
        static constraints = {
          gender(nullable: true)
          spouse(nullable: true)
        }
      }
      """
    And I have created the following "MarriedPerson" graph:
      """
        [
          {
            "name": "Harold",
            "gender": "male",
            "age": 18,
            "spouse": {
              "class": "MarriedPerson",
              "name": "Maude"
            }
          },
          {
            "name": "Maude",
            "gender": "female",
            "age": 57
          },
          {
            "name": "Jeff",
            "gender": "male",
            "age": 26,
            "spouse": {
              "class": "MarriedPerson",
              "name": "Nancy"
            }
          },
          {
            "name": "Nancy",
            "gender": "female",
            "age": 24,
            "spouse": {
              "class": "MarriedPerson",
              "name": "Jeff"
            }
          }
        ]
      """
    When I execute the following code:
      """
      MarriedPerson.where {
        spouse where: {
          age gte: 25
        }
      }.all()
      """
    Then I should get the following results:
      | name    |
      | Nancy   |
      | Harold  |
  
  Scenario: Query using a map
    Given I have the following domain class:
      """
      class FriendlyPerson {
        String name
        String gender
        FriendlyPerson bestFriend
        
        static constraints = {
          gender(nullable: true)
          bestFriend(nullable: true)
        }
      }
      """
    And I have created the following "FriendlyPerson" graph:
      """
        [
          {
            "name": "Harold",
            "gender": "male",
            "bestFriend": {
              "class": "FriendlyPerson",
              "name": "Maude"
            }
          },
          {
            "name": "Maude",
            "gender": "female"
          },
          {
            "name": "Jeff",
            "gender": "male",
            "bestFriend": {
              "class": "FriendlyPerson",
              "name": "Harold"
            }
          },
          {
            "name": "Nancy",
            "gender": "female",
            "bestFriend": {
              "class": "FriendlyPerson",
              "name": "Maude"
            }
          }
        ]
      """
    When I execute the following code:
      """
      FriendlyPerson.where {
        gender mapTo: "friend_gender"
        bestFriend where: {
          gender equals: mapping("friend_gender")
        }
      }.all()
      """
    Then I should get the following results:
      | name    |
      | Nancy   |
      | Jeff  |
{'fraction_non_alphanumeric': 0.1123141564318035, 'fraction_numerical': 0.003232062055591467, 'mean_word_length': 1.12170037709976, 'pattern_counts': {'":': 76, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '642356', 'n_tokens_mistral': 1654, 'n_tokens_neox': 1616, 'n_words': 433}