malcolm-kee / gatsby-source-mysql

Source plugin for pulling data into Gatsby from MySQL database
https://www.npmjs.com/package/gatsby-source-mysql
18 stars 10 forks source link

Many To Many #8

Closed robertwh closed 5 years ago

robertwh commented 5 years ago

Trying the following:

statement: 'SELECT st.SiteID, st.SiteName, st.ExpandedSiteName FROM SiteTable st JOIN ActiveTips t ON st.SiteID = t.SiteID WHERE ((st.Active = 1 AND st.SiteDump = 0) OR st.CopywriterID IS NOT NULL) AND t.DeletedDate IS NULL GROUP BY st.SiteID, st.SiteName, st.ExpandedSiteName HAVING COUNT(*) > 10 ORDER BY st.SiteName', idFieldName: 'TipID', name: 'exploreTipSites'

Which I believe is a many to many join. Doesn't seem to work, is it possible to allow it?

malcolm-kee commented 5 years ago

Thanks for raising the issue. Is TipID returned by the query?

Field Required? Description
idFieldName Required column that is unique for each record. This column must be returned by the statement.
robertwh commented 5 years ago

Yes. Unique to the ActiveTips table

Sent from my iPhone

On Jun 7, 2019, at 8:11 PM, Malcolm Kee notifications@github.com wrote:

Thanks for raising the issue. Is TipID returned by the query?

Field Required? Description idFieldName Required column that is unique for each record. This column must be returned by the statement. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

malcolm-kee commented 5 years ago

Hi @robertwh, try putting SiteID as idFieldName because the idFieldName actually means unique identifier for your query result, not id for your table.

robertwh commented 5 years ago

I'll give that a try, but it's not unique to the rows returned, TipID is.

robertwh commented 5 years ago

Just reran everything with TipID as the idFieldName as well as adding it in to the select statement. Looks like it's working now. Thought for sure this was how I originally tried it and it didn't work. Here is the full code:

      {
        statement: 'SELECT t.TipID, st.SiteID, st.SiteName, st.ExpandedSiteName FROM SiteTable st JOIN ActiveTips t ON st.SiteID = t.SiteID WHERE ((st.Active = 1 AND st.SiteDump = 0) OR st.CopywriterID IS NOT NULL) AND t.DeletedDate IS NULL GROUP BY st.SiteID, st.SiteName, st.ExpandedSiteName HAVING COUNT(*) > 10 ORDER BY st.SiteName',
        idFieldName: 'TipID',
        name: 'exploreTipSites'
      }

Thanks for the help/quick responses!

malcolm-kee commented 5 years ago

@robertwh great! I'll close the issue.