Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
ORM Relation where clause
  • Hi,

    I would like to relate products temporal model to order_products model, based on the order model's timestamp, so the where clause in the has_one should be:

    array('product.temporal_start', '<=', 'order.created_at')

    but of course the 'order.created_at' part is treated as string, not as column name.

    Will it work, or I have to find on products model manually?
  • You need to specify the relation name there, not the model name. Is the relation called 'order'?
  • Yes, it is called order.

    Order --order<-order_product-- Order_Product ---order_product->-product--- Product

  • This is an array from the find() syntax? I never use that, but that should support this notation as well.

    Can you post the full query?

    What if you do:

    $result = Model_Product::query()->related('order')->where('product.temporal_start', '<=', 'order.created_at')->get();
  • As I mentioned the query starts from the Order_Product model, and the array should be part of the join (where condition in the relation).

    I created a gist for it:
    https://gist.github.com/sagikazarmark/6188425

    So it is is in the join not in the query where conditions.

  • This is something that I am missing for a while. I cannot add a join condition with a relation. The 3rd parameter can only be some direct value, the query object does not try to parse it if it is a column name.

    Maybe I am doing something wrong.
  • That is actually quite difficult to fix without a major rewrite of the code, there's already an issue open for it.

    I don't think it's going to be adressed in 1.x, for 2.0 ORM is going to be largely rewritten, so we'll pick it up there...
  • What do you suggest? Currently I set up Observer_Self and on after_load event I manually find the proper revision, but this means a lot more query. As this model contains the ordered products there are about five more queries for each order, so this is not a big problem, but is a bit ugly. :D

    Possible solution would be using the required table name instead of the relation name, but MySQL does not support it.
  • I don't really have a solution at the moment.

Howdy, Stranger!

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

In this Discussion