OK、@infused の提案は良さそうです。これはActiveJDBCでも同じです
最初にモデルを定義します。
public class Customer extends Model {}
public class Merchant extends Model {}
public class Transaction extends Model {}
次に、テーブルを作成します。
顧客:
id | first_name | last_name | etc
商人:
id | name | address1 | etc
取引:
id | customer_id | merchant_id | tag | etc
顧客のすべてのトランザクションを見つける:
customer.getAll(Transaction.class);
マーチャントのすべてのトランザクションを検索するには:
merchant.getAll(Transaction.class);
マーチャント #25 の顧客 #1 のトランザクションをすべて検索します。
customer = Customer.findById(1);
customer.get(Transaction.class, "merchant_id = ?", 25);
顧客 #8 に対する業者 #1 のすべてのトランザクションを見つける
merchant = Merchant.findById(1);
merchant.get(Transaction.class, "customer_id = ?", 8);
タグですべてのトランザクションを検索します (タグが文字列フィールドであると仮定します):
transactions = Transaction.where("tag = ?", "best-seller");
'best-seller' でタグ付けされたトランザクションを持つすべてのマーチャントを検索:
transactions = Transaction.where("tag = 'best-seller'").include(Merchant.class);
//iterate over transactions, and get a merchants:
transactions.get(i).getAll(Merchant.class)
このアプローチは 2 つの SQL クエリのみを実行し、非常に高速です。
これが役立つことを願っています