================================================================================
Relationship Self-Referencing Lookup
================================================================================

SELECT Contact.FirstName, Contact.Account.Name from Contact

--------------------------------------------------------------------------------

    (source_file
      (soql_query_body
        (select_clause
          (field_identifier
            (dotted_identifier
              (identifier)
              (identifier)))
          (field_identifier
            (dotted_identifier
              (identifier)
              (identifier)
              (identifier))))
        (from_clause
          (storage_identifier
            (identifier)))))

================================================================================
Relationship Sub-Select
================================================================================

SELECT Account.Name,
    (SELECT Contact.FirstName, Contact.LastName
    FROM Account.Contacts)
FROM Account

--------------------------------------------------------------------------------

    (source_file
      (soql_query_body
        (select_clause
          (field_identifier
            (dotted_identifier
              (identifier)
              (identifier)))
          (subquery
            (soql_query_body
              (select_clause
                (field_identifier
                  (dotted_identifier
                    (identifier)
                    (identifier)))
                (field_identifier
                  (dotted_identifier
                    (identifier)
                    (identifier))))
              (from_clause
                (storage_identifier
                  (dotted_identifier
                    (identifier)
                    (identifier)))))))
        (from_clause
          (storage_identifier
            (identifier)))))

================================================================================
Relationship Lookup Attributes
================================================================================

SELECT Id, Name, Account.Name
FROM Contact
WHERE Account.Industry = 'media'

--------------------------------------------------------------------------------

    (source_file
      (soql_query_body
        (select_clause
          (field_identifier
            (identifier))
          (field_identifier
            (identifier))
          (field_identifier
            (dotted_identifier
              (identifier)
              (identifier))))
        (from_clause
          (storage_identifier
            (identifier)))
        (where_clause
          (comparison_expression
            (field_identifier
              (dotted_identifier
                (identifier)
                (identifier)))
            (value_comparison_operator)
            (string_literal)))))

================================================================================
Relationship Child Relationship With Lookup
================================================================================

SELECT Name,
  (
    SELECT CreatedBy.Name
    FROM Notes
  )
FROM Account

--------------------------------------------------------------------------------

    (source_file
      (soql_query_body
        (select_clause
          (field_identifier
            (identifier))
          (subquery
            (soql_query_body
              (select_clause
                (field_identifier
                  (dotted_identifier
                    (identifier)
                    (identifier))))
              (from_clause
                (storage_identifier
                  (identifier))))))
        (from_clause
          (storage_identifier
            (identifier)))))

================================================================================
Relationship Child with Deep Lookup
================================================================================

SELECT Amount, Id, Name, (SELECT Quantity, ListPrice,
  PriceBookEntry.UnitPrice, PricebookEntry.Name,
  PricebookEntry.product2.Family FROM OpportunityLineItems)
  FROM Opportunity

--------------------------------------------------------------------------------

    (source_file
      (soql_query_body
        (select_clause
          (field_identifier
            (identifier))
          (field_identifier
            (identifier))
          (field_identifier
            (identifier))
          (subquery
            (soql_query_body
              (select_clause
                (field_identifier
                  (identifier))
                (field_identifier
                  (identifier))
                (field_identifier
                  (dotted_identifier
                    (identifier)
                    (identifier)))
                (field_identifier
                  (dotted_identifier
                    (identifier)
                    (identifier)))
                (field_identifier
                  (dotted_identifier
                    (identifier)
                    (identifier)
                    (identifier))))
              (from_clause
                (storage_identifier
                  (identifier))))))
        (from_clause
          (storage_identifier
            (identifier)))))

================================================================================
Relationship Child with Filter
================================================================================

SELECT Name,
  (
    SELECT LastName
    FROM Contacts
    WHERE CreatedBy.Alias = 'x')
 FROM Account WHERE Industry = 'media'

--------------------------------------------------------------------------------

    (source_file
      (soql_query_body
        (select_clause
          (field_identifier
            (identifier))
          (subquery
            (soql_query_body
              (select_clause
                (field_identifier
                  (identifier)))
              (from_clause
                (storage_identifier
                  (identifier)))
              (where_clause
                (comparison_expression
                  (field_identifier
                    (dotted_identifier
                      (identifier)
                      (identifier)))
                  (value_comparison_operator)
                  (string_literal))))))
        (from_clause
          (storage_identifier
            (identifier)))
        (where_clause
          (comparison_expression
            (field_identifier
              (identifier))
            (value_comparison_operator)
            (string_literal)))))

================================================================================
Relationship Filter on lookup property
================================================================================

SELECT Id, FirstName__c, Mother_of_Child__r.FirstName__c
FROM Daughter__c
WHERE Mother_of_Child__r.LastName__c LIKE 'C%'

--------------------------------------------------------------------------------

    (source_file
      (soql_query_body
        (select_clause
          (field_identifier
            (identifier))
          (field_identifier
            (identifier))
          (field_identifier
            (dotted_identifier
              (identifier)
              (identifier))))
        (from_clause
          (storage_identifier
            (identifier)))
        (where_clause
          (comparison_expression
            (field_identifier
              (dotted_identifier
                (identifier)
                (identifier)))
            (value_comparison_operator)
            (string_literal)))))

================================================================================
Relationship Filter Polymorphic field on Type
================================================================================


SELECT Id, Owner.Name
FROM Event
WHERE Owner.Type = 'User'

--------------------------------------------------------------------------------

    (source_file
      (soql_query_body
        (select_clause
          (field_identifier
            (identifier))
          (field_identifier
            (dotted_identifier
              (identifier)
              (identifier))))
        (from_clause
          (storage_identifier
            (identifier)))
        (where_clause
          (comparison_expression
            (field_identifier
              (dotted_identifier
                (identifier)
                (identifier)))
            (value_comparison_operator)
            (string_literal)))))

================================================================================
Relationship Type in List
================================================================================


SELECT Id
FROM Event
WHERE What.Type IN ('Account', 'Opportunity')

--------------------------------------------------------------------------------

    (source_file
      (soql_query_body
        (select_clause
          (field_identifier
            (identifier)))
        (from_clause
          (storage_identifier
            (identifier)))
        (where_clause
          (comparison_expression
            (field_identifier
              (dotted_identifier
                (identifier)
                (identifier)))
            (set_comparison_operator)
            (string_literal)
            (string_literal)))))