Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
How can I join to the same related table multiple times in single query?
  • Hi, I'm trying to determine if its possible to generate a query similar to the following (I've tried to keep it as simple as possible)
    SELECT product.* from product
    JOIN product_property AS product_property_size
    ON = product_property_size.product_id AND product_property_size.key = 'size'
    // Would want to be able to do this one or more times for different properties
    JOIN product_property AS product_property_color
    ON = product_property_color.product_id AND product_property_color.key = 'color'
    WHERE product_property_size.value = 'big' AND product_property_color.value = 'red'

    As noted in the query above I would be looking to potentially do this several times depending on how many different properties a user is filtering on. I've already got the models defined and relations work when wanting to just do this filtering on a single query. I'm just not sure how I would extend it to doing multiple related joins...
    Thanks, Richard

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!