[Plugin: WP MVC] has_and_belongs_to_many endless query loop
-
Theres a chance I have this set up all wrong but ill do my best to explain.
So i have two tables ‘themes’ and ‘pages’ with a join table ‘themes_pages’ because im trying to keep the tables as normalized as possible. themes can be on many pages and pages can have many themes so I figured the only model relationship that works is the has_and_belongs_to_many, also because this seems to be the only relationship that supports join table configurations.Now I want to have the has_and_belongs_to_many relationship on both the Theme and Page model with the Theme model including the page model and the Page Model including the Theme model when either is queried so I always have access to this data because its important.
It seems as though I cant have the relationship on both models pointing to the other because when I go to the main index controller of either it just hangs. I turned debugging on and its basically an endless loop of sorts that gets spit out until it dies and nothing gets written to the page. I guess I could just choose which one needs to have the relationship more often and drop it from the other and then just append it onto the object in the after_find method, but this seems like an unnecessary extra step.
Heres the debug query:
SELECT Page.id, Page.name FROM
page
Page
JOIN themes_pagesJoinTable
ON JoinTable.page_id = Page.id WHERE JoinTable.theme_id = “9”
SELECT Theme.id, Theme.name FROMtor_themes
Theme
JOIN themes_pagesJoinTable
ON JoinTable.theme_id = Theme.id WHERE JoinTable.page_id = “1”and its just those 2 line over and over and over again until it crashes.
Is the endless loop of querying a bug or is this intended due to this being a bad setup on my part?
What would be a recommended direction i go?Thanks!
- The topic ‘[Plugin: WP MVC] has_and_belongs_to_many endless query loop’ is closed to new replies.