mockmcok
mockmcok

Reputation: 3

Making a exception for @SQLRestriction in querydsl

In my Member Entity I have the following annotation

@SQLRestriction("is_deleted = 0")

There are a lot of code that is already dependent on this condition so removing it would unfortunately not be an option.

However, there is one method in particular where I need to get the info from the member table even for deleted members.

List<MemberManageResponse_v2_0.Subscription> subscriptions = queryFactory
            .select(
                Projections.constructor(
                    MemberManageResponse_v2_0.Subscription.class,
                    subscriptionHistory.memberId,
                    subscriptionHistory.originalTransactionId,
                    subscriptionHistory.id.stringValue(),
                    member.emailAddress,
                    memberProfile.nickname,
                    Expressions.as(
                        Expressions.cases()
                            .when(subscriptionHistory.expiredAt.before(LocalDateTime.now()))
                            .then(Member.SubscriptionStatus.UNSUBSCRIBED)
                            .otherwise(member.subscriptionStatus),
                        "subscriptionStatus"
                    ),
                    subscriptionHistory.subscribedAt,
                    subscriptionHistory.expiredAt
                )
            )
            .from(subscriptionHistory)
            .leftJoin(member).on(subscriptionHistory.memberId.eq(member.memberId))
            .leftJoin(memberProfile).on(subscriptionHistory.memberId.eq(memberProfile.memberId))
            .where(conditions)
            .orderBy(subscriptionHistory.subscribedAt.desc())
            .offset(pageable.getOffset())
            .limit(pageable.getPageSize())
            .fetch();

For members where is_deleted is 1 I seem to be able to fetch other info but I am not able to get the emailAddress and the Subscription Status which are in the member table.

Would there be any method to allow this just on this method without deleting the annotation completely?

Thank you in advance!

Upvotes: 0

Views: 31

Answers (0)

Related Questions