3093 Posts in 875 Topics by 654 members
|Go to End|
13 October 2009 at 9:20am
Can I use a Union in this method?
$query->select = array("blah blah blah");
$query->from = array("blah blah blah");
$query->where = array("blah blah blah");
$query->groupby = array("blah blah blah");
$query->union = array("blah blah blah"); ???
$query->orderby = "blah blah blah";
$query->limit = "blah blah blah";
In the same query I ned to search BOTH the SiteTree table AND some DataObjectManager tables, which is why I need the Union(s). Any ideas?
13 October 2009 at 1:18pm
How about a LEFT JOIN instead, or a HAVING? Those are in there.
Last resort you could just generate the raw SQL and fire it of with DB::query();
13 October 2009 at 2:02pm
Hi, thanks for your reply. I would use DB::query() if I didn't need Pagination. ParseQueryLimit() doesn't work with DB::query(), so I think I Have to use SQLQuery(). And a JOIN won't work because these DataObjectManager-created tables have No relationship to SiteTree. And HAVING, well, I don't know how that would work. Further ideas?
14 October 2009 at 1:33pm
There are a few issues here. Firstly, if you have disparate objects, you have the potential for ID collisions which SilverStripe is not going to like in certain situations. Secondly, it isn't even clear how you paginate over a unioned dataset. Consider the differences between:
(SELECT ID FROM MyObject LIMIT 5) UNION (SELECT ID FROM MyOtherUnrelatedObject LIMIT 5)
(SELECT ID FROM MyObject UNION SELECT ID FROM MyOtherUnrelatedObject) LIMIT 5
Basically, to keep it stable you'll have to write the sql and handle the pagination yourself. You could also try merging two dataobject sets, eg:
$ds1 = DataObject::get('MyObject');
$ds2 = DataObject::get('MyOtherUnrelatedObject');
But it doesn't really make pagination any easier.
16 October 2009 at 6:04pm
I can't see how any type of relationship created by the ORM would not be joinable with SQLQuery and formatting into a DataSetObject. Have you tried getting into your data via a real query browser?
17 October 2009 at 10:22am
Yes. And I am using DB::query() now because of this Union issue. I just have to go with no paging, I guess, or try the merge() as suggested by @hamish.
|Go to Top|