Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

is there any way I can do this in a get() call?


Go to End


3 Posts   865 Views

Avatar
mi32dogs

Community Member, 75 Posts

8 May 2015 at 5:22pm

Edited: 08/05/2015 5:27pm

I have a question, I have a database query for a events site is there any way I can do this in a get() call so I can keep the has_one relations?

My query:

$records = DB::query("SELECT
				b.Name, b.InfoPage, (b.ID) AS VenueID,  (b.List) AS VenueList,
				alias_event.*,
				min(StartDateTime) AS firstdate,
				GROUP_CONCAT( StartDateTime ORDER BY StartDateTime ASC ) AS alldates,
				GROUP_CONCAT( alias_event.id ORDER BY StartDateTime ASC) AS allids
			FROM ( SELECT 
					* 
				FROM 
					event
				WHERE
					List = 'true' AND
					StartDateTime >= NOW() AND
					((ListDate IS NULL OR ListDate = '') OR ListDate < NOW())
				ORDER BY StartDateTime DESC
				) AS alias_event
				LEFT JOIN locations AS b ON alias_event.LocationID = b.ID
				LEFT JOIN file AS c ON alias_event.EventImageID = c.ID
				LEFT JOIN file AS d ON alias_event.EventBannerID = d.ID
			WHERE
				alias_event.List = 'true' AND
				StartDateTime >= NOW() AND
				 ((ListDate IS NULL OR ListDate = '') OR ListDate < NOW())
			GROUP BY 
				CONCAT_WS(
					',',
					Artist,
					Support,
					Special,
					OnsaleDateTime > NOW(),
					IF(EventStatus = 'Soldout', '' , EventStatus)
				)
			ORDER BY 
				StartDateTime ASC"

Avatar
Pyromanik

Community Member, 419 Posts

11 May 2015 at 11:08pm

Not with the group concat, no.
You might be able to pull out the DataQuery, modify it, and plonk it back into the list, but it seems more trouble than it's worth.

Group concat is rather ineffeicient and is MySQL only, I don't recommend it.

You didn't explain the business logic behind the query, so I can only make a poor guess as to what you're trying to do.
And the usual simple <% loop Things %> etc would be sufficient in this case I should imagine, referencing the relationships where necessary.

Avatar
mi32dogs

Community Member, 75 Posts

12 May 2015 at 4:07pm

Thank you Pyromanik