Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

combination of persistent and non-persistent objects responds empty relationship list for include on Cayenne entity #475

Open
vitalz opened this issue Dec 23, 2020 · 0 comments

Comments

@vitalz
Copy link

vitalz commented Dec 23, 2020

Combination of persistent and non-persistent objects responds empty lists for includes on Cayenne entity

Cayenne version: 4.0
AgRest version: 3.1

There is an example of aggegiated object responded.

Rest API endpoint:

    @GET
    public DataResponse<PlayerMatch> getMatches(@PathParam("id") int id, @Context UriInfo uriInfo) {
        return Ag.select(PlayerMatch.class, config)
                .stage(SelectStage.CREATE_ENTITY, (SelectContext<PlayerMatch> t) -> {
                    t.getEntity().setFiltered(true);
                })
                .terminalStage(SelectStage.APPLY_SERVER_PARAMS, (SelectContext<PlayerMatch> t) -> { // terminal stage because of ${jira_issue_number}; server params brings includes and then it might be terminated
                    t.getEntity().setResult(matchPlayerService.getPlayerMatches(id));
                })
                .uri(uriInfo).get();
    }

There is custom PlayerMatch object where @AgRelationship annotated Player is Cayenne object

public class PlayerMatch {
	private int matchPriority;
	private Player player;
	
	public PlayerMatch() {	
	}
	
	public PlayerMatch(int matchPriority, Player player) {
		this.matchPriority = matchPriority;
		this.player = player;
	}
	
	@AgAttribute
	public int getMatchPriority() {
		return matchPriority;
	}
	
	public void setMatchPriority(int matchPriority) {
		this.matchPriority = matchPriority;
	}
	
	@AgRelationship
	public Player getPlayer() {
		return player;
	}
	
	public void setPlayer(Player player) {
		this.player = player;
	}
	
}	

And the same time Player has Cayenne relationship which is in interest to be included in response:

public abstract class _Player extends CayenneDataObject {
    // ...
    public static final Property<List<RosterSpot>> ROSTER_SPOTS = Property.create("rosterSpots", List.class);

When rest api endpoint requested with /rest/playermatch?include=player&include=player.rosterSpots it will response player data but [] for rosterSpots field though they are existing on database (also there is no sql query for roster spots include in log), i.e. like:

{
  matchPriority: 1,
  player: {
    id: 1,
    rosterSpots: [ ],
    name: "Joe Doe"
  },
  player_id: 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant