package com.rainmakeross.krazyideas.models;

import lombok.Data;

import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;

@Entity
@Data
public class Idea {
    @Id
    @GeneratedValue(strategy= GenerationType.AUTO)
    private long id;
    private String name;
    private String description;
    private String shortDescription;

    @OneToMany
    @JoinColumn(name="id")
    private List<Vote> votes;

    public Idea() {
    }

    public Idea(String name, String description) {
        this.name = name;
        this.description = description;
    }

    @Override
    public String toString() {
        return String.format(
            "Idea[id=%d, name='%s', description='%s']",
            id, name, description);
    }

}

@@ -57,16 +57,58 @@
 ok.Data;
+%0Aimport org.hibernate.annotations.Formula;
 %0A%0Aimport
@@ -551,16 +551,331 @@
 ption;%0A%0A
+    @Formula(%22(select count(*) from vote v where v.idea_Id = id)%22)%0A    private int voteCount;%0A%0A    // this is anther option to calculate voteCount%0A    /*private transient int voteCount;%0A%0A    public int getVoteCount()%7B%0A        if (votes==null) %7B%0A            return 0;%0A        %7D%0A        return votes.size();%0A    %7D*/%0A%0A
     @One

add vote count