Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

DATAREST-1280 Add support sort collection resource by associated property. #2328

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

Open
mikoto2000 wants to merge 1 commit into spring-projects:main
base: main
Choose a base branch
Loading
from mikoto2000:issue/DATAREST-1280

Conversation

@mikoto2000
Copy link

@mikoto2000 mikoto2000 commented Nov 13, 2023

Closes #1641
Related tickets #1386 #1343

I delete those code and execute sort 4 patterns.

if (associations.isLinkableAssociation(persistentProperty)) {
return Collections.emptyList();
}

Currently, it seems to support linkable associations.
Therefore, I have removed the check process for linkable associations.

Are there any other patterns that should be tested further?

Patterns result:

eager and exported

Path: /accounts_eager_and_exported?sort=accountType.typeName,desc

Query:

Hibernate: select a1_0.id,a1_0.account_type_id,a1_0.name from account a1_0 left join account_type a2_0 on a2_0.id=a1_0.account_type_id order by a2_0.type_name desc offset ? rows fetch first ? rows only
Entity: AccountEagerAndExported.java
package dev.mikoto2000.study.springboot.data.rest.example.entity;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import lombok.Data;
import org.springframework.data.rest.core.annotation.RestResource;
@Data
@Entity
@Table(name = "account")
public class AccountEagerAndExported {
 @Id
 @GeneratedValue(strategy = GenerationType.AUTO)
 private Long id;
 private String name;
 @RestResource(exported = true)
 @JoinColumn(name = "account_type_id")
 @ManyToOne(fetch = FetchType.EAGER)
 private AccountType accountType;
}
Repository: AccountEagerAndExportedRepository.java
package dev.mikoto2000.study.springboot.data.rest.example.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import dev.mikoto2000.study.springboot.data.rest.example.entity.AccountEagerAndExported;
@RepositoryRestResource(collectionResourceRel = "accounts_eager_and_exported", path = "accounts_eager_and_exported")
public interface AccountEagerAndExportedRepository extends JpaRepository<AccountEagerAndExported, Long> {
 
}
eager and no exported

Path: /accounts_eager_and_no_exported?sort=accountType.typeName,desc

Query:

Hibernate: select a1_0.id,a1_0.account_type_id,a1_0.name from account a1_0 left join account_type a2_0 on a2_0.id=a1_0.account_type_id order by a2_0.type_name desc offset ? rows fetch first ? rows only
Entity: AccountEagerAndNoExported.java
package dev.mikoto2000.study.springboot.data.rest.example.entity;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import lombok.Data;
import org.springframework.data.rest.core.annotation.RestResource;
@Data
@Entity
@Table(name = "account")
public class AccountEagerAndNoExported {
 @Id
 @GeneratedValue(strategy = GenerationType.AUTO)
 private Long id;
 private String name;
 @RestResource(exported = false)
 @JoinColumn(name = "account_type_id")
 @ManyToOne(fetch = FetchType.EAGER)
 private AccountType accountType;
}
Repository: AccountEagerAndNoExportedRepository.java
package dev.mikoto2000.study.springboot.data.rest.example.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import dev.mikoto2000.study.springboot.data.rest.example.entity.AccountEagerAndNoExported;
@RepositoryRestResource(collectionResourceRel = "accounts_eager_and_no_exported", path = "accounts_eager_and_no_exported")
public interface AccountEagerAndNoExportedRepository extends JpaRepository<AccountEagerAndNoExported, Long> {
 
}
lazy and exported

Path: accounts_lazy_and_exported?sort=accountType.typeName,desc

Query:

Hibernate: select a1_0.id,a1_0.account_type_id,a1_0.name from account a1_0 left join account_type a2_0 on a2_0.id=a1_0.account_type_id order by a2_0.type_name desc offset ? rows fetch first ? rows only
Entity: AccountLazyAndExported.java
package dev.mikoto2000.study.springboot.data.rest.example.entity;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import lombok.Data;
import org.springframework.data.rest.core.annotation.RestResource;
@Data
@Entity
@Table(name = "account")
public class AccountLazyAndExported {
 @Id
 @GeneratedValue(strategy = GenerationType.AUTO)
 private Long id;
 private String name;
 @RestResource(exported = true)
 @JoinColumn(name = "account_type_id")
 @ManyToOne(fetch = FetchType.LAZY)
 private AccountType accountType;
}
Repository: AccountLazyAndExportedRepository.java
package dev.mikoto2000.study.springboot.data.rest.example.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import dev.mikoto2000.study.springboot.data.rest.example.entity.AccountLazyAndExported;
@RepositoryRestResource(collectionResourceRel = "accounts_lazy_and_exported", path = "accounts_lazy_and_exported")
public interface AccountLazyAndExportedRepository extends JpaRepository<AccountLazyAndExported, Long> {
 
}
lazy and no exported

In the first place, it is not supported by Spring Data REST.

Example code repository: https://github.com/mikoto2000/spring-data-rest-example

  • You have read the Spring Data contribution guidelines.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

clementdenis and msparer reacted with thumbs up emoji
@mp911de mp911de self-assigned this Nov 27, 2023
@mp911de mp911de added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 27, 2023
Copy link
Author

@mp911de
What is it duplicated with? Is there any plan for improvement?

Copy link
Contributor

Any news on this? We'd really like to be able to sort by fields in linked associations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Labels

status: duplicate A duplicate of another issue

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Sort collection resource by associated property [DATAREST-1280]

AltStyle によって変換されたページ (->オリジナル) /