I have setup 2 models in ebean, both work fine when queried separately. Now i need to get into my Show.scala.html fields from both my product & heading models, the product fields work fine but I also need the DateOrder from heading, but I am getting a compilation error of value DateOrder is not a member of object models.Heading, please help
My Models
package models;
import io.ebean.Finder;
import io.ebean.Model;
import play.data.validation.Constraints;
import javax.persistence.*;
import java.util.Date;
import java.util.List;
@Entity
@Table(name="Heading")
public class Heading extends Model {
@Id
@Column(name="JobKeyID")
public Integer JobKeyID;
@Constraints.MaxLength(50)
@Constraints.Required
@Column(name="Name")
public String Name;
@Column (name="JobNumber", columnDefinition = "NVARCHAR")
public String JobNumber;
@Constraints.Required
@Column(name="SellingPriceIncTax")
public Integer SellingPriceIncTax;
@Constraints.Required
@Column(name="DateOrder")
public Date DateOrder;
@Column(name="CustomerID")
public Integer CustomerID;
@OneToMany(mappedBy = "heading", fetch = FetchType.EAGER)
public List<Product> product;
public static Finder<Integer, Heading> find = new Finder<>(Heading.class);
}
package models;
import io.ebean.Finder;
import io.ebean.Model;
import io.ebeaninternal.server.type.ScalarTypeJsonList;
import play.data.validation.Constraints;
import javax.persistence.*;
import java.util.Date;
import java.util.List;
@Entity
@Table(name="Product")
public class Product extends Model {
@Id
@Column(name = "ItemKeyID")
public Integer ItemKeyID;
@Constraints.MaxLength(50)
@Constraints.Required
@Column(name = "ProductName")
public String ProductName;
@Column(name = "ItemNumber")
public Integer ItemNumber;
@Constraints.Required
@Column(name = "DesignName")
public String DesignName;
@Column(name = "JobKeyID")
public Integer JobKeyID;
@ManyToOne
@JoinColumn(name="JobKeyID")
public Heading heading;
@OneToMany(mappedBy = "product")
public List<Information> information;
public static Finder<Integer, Product> find = new Finder<>(Product.class);
}
My Controller
public Result show(Integer id){
List<Product> products = Ebean.find(Product.class)
.fetch("heading")
.where().eq("JobKeyID",id)
.setFirstRow(0)
.setMaxRows(10)
.findList();
return ok(show.render(products)) ;
}
and my scala.html
@(products : List[Product])
@Layout("All Books") {
<h1> All Books</h1>
@for(product <- products) {
<a class="btn btn-link" href="@routes.BooksController.specinfo(product.JobKeyID, product.ItemKeyID)">@product.ProductName</a>
<p> Design Name : @product.DesignName</p>
<p> Order Date : @Heading.DateOrder</p>
<img src ="@routes.ImagesController.getImage("419326-1.svg")"/>
}
}
You're trying to get field DateOrder via class, but it's not a static member. I believe it's the cause. If I understood your intention correctly, you should replace @Heading.DateOrder
with @product.heading.DateOrder
.