View more context

 

Aaron Cooper

Deleting them from the file system, or from the DB too?

Ben

from the file system. The sync should have removed them from the db right?

Aaron Cooper

Yeah probably. I'm just wondering if the bottleneck is just in the DB call for the records or something SS does with the file system on load.

customPhpDev

Is there a way to get distinct records using ORM?

customPhpDev

Here is my code and want to apply distinct on MemberID field.

customPhpDev
  1. $Orders = Order::get()->filter([
  2. 'ID:GreaterThan' => 287
  3. ]);
jkersu

Do you want to do get just a list of distinct MemberIDs? You can do:

  1. $Orders = Order::get()->filter([
  2. 'ID:GreaterThan' => 287
  3. ])->column('MemberID');
customPhpDev

I tried it but still I am getting the record more than single time.

jkersu

Which record are you trying to get? Order or Member?

jkersu

ID should be unique as well, so you should be returning a single Order record only once, in a list already?

customPhpDev

Of course I want to get Order records but my records have MemberID as well and I want to get them uniquely.

customPhpDev
  1. $Orders = Order::get()->filter([
  2. 'Created:GreaterThanOrEqual' => '2019-11-07 00:00:00'
  3. ])->distinct(true)->column('MemberID');
customPhpDev
  1. (
  2. [0] => 1
  3. [1] => 1
  4. [2] => 1
  5. [3] => 5009
  6. [4] => 6330
  7. [5] => 6325
  8. [6] => 6299
  9. [7] => 2212
  10. [8] => 6322
  11. [9] => 6320
  12. [10] => 6320
  13. [11] => 6293
  14. [12] => 2232
  15. [13] => 6319
  16. [14] => 6318
  17. [15] => 3806
  18. [16] => 5376
  19. [17] => 6316
  20. [18] => 6007
  21. [19] => 1349
  22. [20] => 6311
  23. [21] => 5217
  24. [22] => 6308
  25. [23] => 5830
  26. [24] => 3159
  27. [25] => 5166
  28. [26] => 6307
  29. [27] => 2970
  30. [28] => 489
  31. [29] => 184
  32. [30] => 38
  33. )
jkersu

Try either of these:

  1. $Orders = array_unique(Order::get()->filter([
  2. 'ID:GreaterThan' => 287
  3. ])->column('MemberID'));

OR

  1. $Orders = Order::get()->filter([
  2. 'ID:GreaterThan' => 287
  3. ])->columnUnique('MemberID');
MichalKleiner

in SS3 the column method wasn’t unique/distinct, there could be duplicates

customPhpDev
  1. $Orders = array_unique(Order::get()->filter([
  2. 'ID:GreaterThan' => 287
  3. ])->column('MemberID'));
nightjarnz

Alternatively, query it in reverse. Member::get()->filter('Orders.ID:GreaterThan', 287)


Show less replies