AndCondition question
Hello,
I'm a newbie to this framework, so need some help.
I don't quite understand why I'm getting an error like this:
"Cannot use QQNode for "order_data" when querying against the "order" table".
Call of QuerySingle looks like this:
$this->objOrder = Product::QuerySingle(
QQ::AndCondition(QQ::Equal(QQN::Order()->Id, $intOrderId),
QQ::Equal(QQN::OrderData()->Id, 1)),
QQ::Clause(QQ::Expand(QQN::Order()->OrderInvoice),
QQ::Expand(QQN::Order()->OrderData))
);
Problem occurs with AndCondition. When I leave only one condition
QQ::Equal(QQN::Order()->Id, $intOrderId) - then it works.
But if I need two, then got error. Joining the tables works, I printed out
resulting sql query, it was correct.
Another question, is there any standard way of logging in this framwork?
Thanks in advance!

Forgot to add, beginning of call stack, where error occurs:
#0 C:\...\lib\includes\qcodo\_core\framework\QQuery.class.php(828): QQNode->GetColumnAlias(Object(QQueryBuilder))
#1 C:\...\lib\includes\qcodo\_core\framework\QQuery.class.php(531): QQConditionEqual->UpdateQueryBuilder(Object(QQueryBuilder))
It should be
QQ::Equal(QQN::Order()->OrderDataID, 1))
or something like that. The first QQuery node in the expression should match your original table - and then you expand from there.
Thanks for reply!
But I think it's not quite right.
I have two tables.
"order" and "order_data". They are joined using one-to-many relationship. In "order_data" table there is a field orderID, which is FK of table "order". It is working.
In this example I need to add two conditions:
1) Find record in "order" table with given ID.
2) There could be several records in table "order_data", so I need to filter out only one with given rowID.
In my previous mail I simplified the example. It should be actually smth like this:
QQ::AndCondition(
QQ::Equal(QQN::Order()->Id, $intOrderId),
QQ::Equal(QQN::OrderData()->rowId, $intRowId))
In SELECT which is created, they should be from different tables, like "t0".Id=1 AND "t1".rowId=5. At least I expect that query will be like this... :)
Maybe picture is a bit more clearer?
If you want just one order_data record in the result, try doing
OrderData::querySingle,
and you'll have access to all id's right there. If I'm misunderstanding you, can you post full schema definition.
If you want to get multiple orderdata records, try doing a query array on the order table, and then expandAsArray on order_data (see example at http://examples.qcu.be/assets/_core/php/examples/qcubed_query/expandasar...)
Basically, within a single query, you can only use one QQN::* name, and it must match the class you're calling the query on.
So if you use Product::QuerySingle, you have to start every QQN stack at QQN::Product.
So if you want the Order where the Order Id is $intOrderId and it has an orderdata with RowId $intRowId, you'd end up with the following:
$order = Order::QuerySingle(QQ::AndCondition(
QQ::Equal(QQN::Order()->Id, $intOrderId),
QQ::Equal(QQN::Order()->OrderRows->RowId, $intRowId)
)
QQ::Clause(QQ::Expand(QQN::Order()->OrderRows))
);
$row = $order->_OrderRows; //This doesn't take a DB hit due to the expand
Hi there,
It should be
QQ::Equal(QQN::Order()->OrderRowsObject->RowId, $intRowId)
not :
QQ::Equal(QQN::Order()->OrderRows->RowId, $intRowId)
No ?
I guess it depends on if your foreign key column is named order_row or order_row_id.