package org.avaje.ebean.typequery;

import com.avaje.ebean.ExpressionList;

/**
 * Base type for associated beans.
 *
 * @param <T> the entity bean type (normal entity bean type e.g. Customer)
 * @param <R> the specific root query bean type (e.g. QCustomer)
 */
public abstract class TQAssocBean<T, R> {

  protected final String name;

  protected final R root;

  /**
   * Construct with a property name and root instance.
   *
   * @param name the name of the property
   * @param root the root query bean instance
   */
  public TQAssocBean(String name, R root) {
    this(name, root, null);
  }

  /**
   * Construct with additional path prefix.
   */
  public TQAssocBean(String name, R root, String prefix) {
    this.root = root;
    this.name = TQPath.add(prefix, name);
  }

  /**
   * Internal method to return the underlying expression list.
   */
  protected ExpressionList<?> expr() {
    return ((TQRootBean) root).peekExprList();
  }

  /**
   * Is equal to by ID property.
   */
  public R equalTo(T other) {
    expr().eq(name, other);
    return root;
  }

  /**
   * Is not equal to by ID property.
   */
  public R notEqualTo(T other) {
    expr().ne(name, other);
    return root;
  }

  /**
   * Apply a filter when fetching these beans.
   */
  public R filterMany(ExpressionList<T> filter) {

    ExpressionList<T> expressionList = (ExpressionList<T>)expr().filterMany(name);

    expressionList.addAll(filter);
    return root;
  }
}

@@ -319,24 +319,25 @@
 inal String 
+_
 name;%0A%0A  pro
@@ -351,16 +351,17 @@
 final R 
+_
 root;%0A%0A 
@@ -720,16 +720,17 @@
    this.
+_
 root = r
@@ -743,16 +743,17 @@
    this.
+_
 name = T
@@ -921,16 +921,17 @@
 otBean) 
+_
 root).pe
@@ -1038,16 +1038,17 @@
 pr().eq(
+_
 name, ot
@@ -1056,32 +1056,33 @@
 er);%0A    return 
+_
 root;%0A  %7D%0A%0A  /**
@@ -1172,16 +1172,17 @@
 pr().ne(
+_
 name, ot
@@ -1190,32 +1190,33 @@
 er);%0A    return 
+_
 root;%0A  %7D%0A%0A  /**
@@ -1396,16 +1396,17 @@
 terMany(
+_
 name);%0A%0A
@@ -1451,16 +1451,17 @@
  return 
+_
 root;%0A  

Rename fields on TQAssocBean to avoid clashes