Search code examples
javaplayframeworkebean

how to show specific field use ebean relation


... is my code

    @ManyToOne
    @JoinColumn(name = "destination_country_id", referencedColumnName = "id", table = "countries", insertable = false, updatable = false)
    public Country country;

...

is the result

"id": 139,
"country": {
            "id": 1,
            "iso": "AU",
            "name": "Australia",
            },
"country_id": 1

...

I hope the result is

"id": 139,
"country": "australia",
"country_id": 1,

...


Solution

  • add this code and change to private in var country

    @Column(name = "name", table = "countries")
    public String country_name;
    

    this is a new my code

    @ManyToOne
    @JoinColumn(name = "destination_country_id", referencedColumnName = "id", table = "countries", insertable = false, updatable = false)
    private Country country;
    
    @Column(name = "name", table = "countries")
    public String country_name;