2

How to do this with one mysql request:

$revision = $this->Revision->where('batch', $batch)->first();

$revisions = $this->Revision->where('batch','>', $batch)
->where('revisionable_type', $revision->revisionable_type)
->where('revisionable_id', $revision->revisionable_id)
->get();

$this->Revision = eloquent model;

others are just columns.

duellsy
  • 8,497
  • 2
  • 36
  • 60
Hontoni
  • 1,332
  • 1
  • 16
  • 27
  • You just want a raw MySQL query for this? Is there a particular reason? Why are you needing to do it that way? – Sturm Feb 23 '14 at 18:53
  • i'm not going to use $revision later, so my thoughts are maybe I can make the mysql remember $revision and give me $revisions directly. And Im not interested in raw query as much as in query builder methods. – Hontoni Feb 24 '14 at 09:10
  • @duellsy not directly related to Revisionable, but ok =) – Hontoni Feb 24 '14 at 09:17
  • actually tagged it `revisionable` so I can easily find it later when working on v2 ;) – duellsy Feb 24 '14 at 10:16

1 Answers1

2

I misunderstood your question initially. You can do this by using:

$sql = "SELECT * FROM revisions AS tmpa 
        INNER JOIN revisions AS tmpb 
        ON tmpb.revisionable_type = tmpa.revisionable_type 
        AND tmpb.revisionable_id = tmpa.revisionable_id 
        WHERE tmpa.batch = '$batch'";

DB::select(DB::raw($sql));
Sturm
  • 4,105
  • 3
  • 24
  • 39