AddFieldToFilter And inside OR condition

I want to achieve the following query in magento custom model.

select * form calendar where date >='2015-04-13' AND start_date <='2015-04-14' AND (is_available != 1 or  (is_available == 1 and rooms_avil<=0))

How to achieve this in magento with AddFieldToFilter ? Not AddAttributeToFilter.


Method addAttributeToFilter is used for module whose model supports EAV structure like: catalog/category, catalog/product etc. We generally use addFieldToFitler for custom module (whose model doesn’t support EAV structure)

Answering on your question: how to create

condition OR (condition AND condition)

I think you can't do it using addFieldToFilter. So my advice is:

->getSelect()->where( /* put here all of your conditions */)

Similar questions

AND inside OR in where condition in getCollections()
Need to generate the following query with getCollection() however unable to figure it out. (id_path = '12/xyz') OR (request_path = '/abc' AND store_id = '1') Tried the following but I need it the other way: //gives (...) AND (.. OR ..)
if statement attribute condition & categories condition (2 conditions)
I have a large amount of products, about half do not have a proper description. To address this I've created an if statement that will display the product name one way and if the condition is not met then it will display it another. Example: Now, I'd like to go a step further with the above rule and set it so that if the product_updated attribute i...
How to add validate() new condition in module-sales-rule/Model/Rule/Condition/Address.php?
Need to add new condition in validate() function of module-sales-rule/Model/Rule/Condition/Address.php by overriding this class in custom module. This function is called on checkout page in frontend when cart price rule is applied via 'Free Shipping' I have tried using both preference & plugin but both not working Please advice, It will be real...
Magento Shopping Cart Rule Condition - Custom condition quote id
I want dynammically create a shopping cart rule to apply to particular quote id. Any suggestion to do that?
Magento2 addFieldToFilter, Need 'and' and 'Or' in sql
I need magento sql collection. Query need like that. select * from custom_table where customer_id=xx or (customer_group=1 and custom_field=1) I can add or operator like below select * from custom_table where customer_id=xx or (customer_group=1) But needs to and operator with second OR. My Current collection: Query From above collection: SELECT main...
convert sql query to magento addFieldToFilter combine OR and AND
You can convert me this sql I did not arrive at combined OR and AND at the same time SELECT * FROM sales_order AS main_table, sales_order_payment AS sop WHERE ((status = 'processing') Or ((status = 'pending') and (sop.method = 'chekmo') )) AND (updated_at >= '2020-06-19 18:24:59') Please, can someone help or suggest anything?

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.