ActiveRecord how to correctly exclude records with conditions correctly?


sgmichelsen
HOME ยป Programming Languages

Why does below not work?
Try to exclude all the is_reply = 1 values from the query but can't figure out how to.
I tried several combinations but all fail.


All records with is_reply = 1 still get returned with this below query, I think need to sub the or part but how?


@messages = Message.all(:conditions => ['is_reply = ? AND recipient_id
= ? OR user_id = ?', 0, current_user.id, current_user.id] )



Related to : ActiveRecord how to correctly exclude records with conditions correctly?
ActiveRecord how to correctly exclude records with conditions correctly?
Programming Languages

Why does below not work?
Try to exclude all the is_reply = 1 values from the query but can't figure out how to.
I tried several combinations but all fail.


All records with is_reply = 1 still get returned with this below query, I think need to sub the or part but how?


@messages = Message.all(:conditions => ['is_reply = ? AND recipient_id
= ? OR user_id = ?', 0, current_user.id, current_user.id] )



Exclude records verifying two conditions
Programming Languages

select * from table_name
where BaseDocEntry=15 and BaseDocType='PRRH' and ItemCode='TestStudy2'
and WhseCode='01' and (currentdoctype<>'PUSH' and CurrentDocEntry<>15)

According to the query I have written above, the data from INS2 will be fetched excluding the currentdoctype [PUSH] and all data where CurrentDocEntry is not 15. What I expect my query to be is, it must exclude the data only if this combination i.e. currentdoctype=PUSH and CurrentDocEntry=15 are occurring in the same row, then exclude that row.


Can you fix this query ?


Rails: ActiveRecord is not parsing time correctly
Programming Languages

I'm assigning a time value in model with


self.started_at = Time.now


When I save it, I get following:


Created at: 2012-05-05 12:11:54 +0200
Started at: 2000-01-01 10:12:06 UTC

I've tried formatting with Time.now.to_s(:db) but the result is the same. Does this depend on locale settings? (I have activerecord 3.1.3)


I'm not sure if I am using the conditions correctly
Programming Languages

I'm not sure if I am using the conditions correctly
 
I have a rule of conditions for access into an area of my site. The problem is, that when the wrong password is given, its still giving access to the area of the site. It is happening because I am using conditions wrong, and ask if someone could help me out by pointing out the correct way to do it.
When I say "conditions", I am referring to things such as && and ||

PHP Code:


HD Wallpapers
3D
3D Abstract
City
Celebrities
Indian Celebrities
Cars
Travel
Girls
Animals Birds
Movies
Sports
Black White
Nature
Planes
Anime
Food Drink
Dreamy Fantasy
Architecture
Games
Space
Holidays
Flowers
Love
Artistic
Baby
Beach
Bikes Motorcycles
Macro
Computers
Vector
Funny
Army
Textures
Brands
Misc
Music
Other
Privacy Policy - Copyrights Notice - Feedback - Report Violation - RSS 2017 © bighow.org All Rights Reserved .