CodeIgniter Forums

Full Version: Datamapper - getting items related to an object .. but not related?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]drakeonfire[/eluser]
Hello,

The Title may of been a bit confusing, I couldn't think how best to word it as it's a fairly lengthy explanation.

For the purpose of the example, I will say it's a Content Management System, which allows pages to be added, categories and blog posts. All of these are located at the root of the site, e.g. example.com/blog_post example.com/category_1

I have a links table to handle all of the links, one column is called type, which defines what type the link is, which enables it to determine what to load in to the page. Let's say 0 = Page, 1 = Category and 2 = Blog Post.
It then has a column called rel_id, which is the ID relevant to the link. These are obviously not unique, as you may have a Blog Post with an ID of 2 and a Category with an ID of 2. It's used to pull the content from the correct table after finding the type of the page.

But anyway - onto the problem.

I'm trying to list all pages (not blog posts, not categories, Just pages) and I want to include the relevant data from the links table. I would hope to do this in a query, otherwise I'll just have to loop through the data until I find a type = 0 and the right rel_id.

Any ideas?

I was thinking a subquery might of worked, but wasn't sure how to make it so it checks for type = 0 and then rel_id = X

Thank you. I hope that makes sense!