conditional-statements

Rails associations: How do I limit/scope a has_many :through with multiple self-referencing conditions?

偶尔善良 提交于 2019-12-06 16:09:18
问题 What's the best way to do this? I'm trying something like this, but it feels... wrong. (NOTE: It's all about the :conditions in the has_many association...) class Submission < ActiveRecord::Base belongs_to :checklist has_many :jobs, :through => :checklist, :source => :job, :conditions => ["jobs.archived = false OR jobs.archived_at > #{self.created_at} OR jobs.created_at < #{self.created_at}"] end Rails 3.2.11, Ruby 1.9.3 What I'm trying to do I need to pass multiple conditions on a has_many

rails - find with condition in rails 4

我的梦境 提交于 2019-12-06 15:40:45
问题 I recently upgraded my rails to Rails 4.1.6. This query used to work : @user = User.find(:all, :conditions => { :name => 'batman' }) Now I get this error message: Couldn't find all Users with 'id': (all, {:conditions=>{:name=>"batman"}}) (found 0 results, but was looking for 2) When I check the logs I can see that rails is trying to do a completely different query : User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" IN ('all', '--- :conditions: :name: batman ') It looks like,

Wordpress conditional statements for taxonomy, term, inside a loop not working

我的梦境 提交于 2019-12-06 14:54:43
问题 This is such a basic problem I'm having but I've tried so many different functions and can't get any to work. On my wordpress website I have created a taxonomy called ' file-formats ' and in this taxonomy I have created these terms (I think these are terms?)... PDF , MOV , PPT and DOC See screenshot below... The problem I have which I can't seem to figure out, is I have a simple WP_Query loop, see below... <?php $downloads = new WP_Query(array( 'post_type' => 'downloads', 'order' => 'ASC',

Pandas and apply function to match a string

岁酱吖の 提交于 2019-12-06 13:57:32
I have a df column containing various links, some of them containing the string "search" . I want to create a function that - being applied to the column - returns a column containing "search" or "other" . I write a function like: search = 'search' def page_type(x): if x.str.contains(search): return 'Search' else: return 'Other' df['link'].apply(page_type) but it gives me an error like: AttributeError: 'unicode' object has no attribute 'str' I guess I'm missing something when calling the str.contains(). I think you need numpy.where : df = pd.DataFrame({'link':['search','homepage d','login dd',

R - vectorised conditional replace

柔情痞子 提交于 2019-12-06 09:39:15
问题 Hi I'm trying manipulate a list of numbers and I would like to do so without a for loop, using fast native operation in R. The pseudocode for the manipulation is : By default the starting total is 100 (for every block within zeros) From the first zero to next zero, the moment the cumulative total falls by more than 2% replace all subsequent numbers with zero. Do this far all blocks of numbers within zeros The cumulative sums resets to 100 every time For example if following were my data : d <

Conditional inner join statements in MySQL

廉价感情. 提交于 2019-12-06 09:19:09
问题 Is there a way I can conditionally change which table i'm inner joining on based on the value of a field in another table? Here's what I got so far (but it errors) out: SELECT j.jobID, j.jobNumber, CASE WHEN j.idType = 'dealership' THEN d.dealershipName WHEN j.idType = 'Group' THEN g.groupName WHEN j.idType = 'Agency' then a.agencyName END as dealershipName, CASE WHEN p.manualTimestamp != '0000-00-00 00:00:00' THEN UNIX_TIMESTAMP(p.manualTimestamp) WHEN p.manualTimestamp = '0000-00-00 00:00

add column to data frame, testing categorical variable in other column

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 08:59:33
问题 I have referred: How to add a factor column to dataframe based on a conditional statement from another column?, How to add column into a dataframe based on condition in R programming and R: Add column with condition-check on three columns? . All the examples are are based on testing for either numeric vectors or NA in other columns and adding a new variable. Here's a short reproducible example: x <- c("dec 12", "jan 13", "feb 13", "march 13", "apr 13", "may 13", "june 13", "july 13", "aug 13"

SQL Conditional JOIN column [duplicate]

拈花ヽ惹草 提交于 2019-12-06 08:54:14
问题 This question already has answers here : SQL Conditional AND (4 answers) Closed 5 years ago . I want to determine the JOIN column based on the value of the current row. So for example, my job table has 4 date columns: offer_date, accepted_date, start_date, reported_date. I want to check against an exchange rate based on the date. I know the reported_date is never null, but it's my last resort, so I have a priority order for which to join against the exchange_rate table. I'm not quite sure how

Conditional content in Mandrill template

半城伤御伤魂 提交于 2019-12-06 07:08:17
问题 I am handing over dictionary keys (key value pair) to a service which in turn utilizes the api to send the email via Mandrill. Now, if my key is blank then i dont want it to be included in the email. Like in the following scenario, i only want the link text to display if my key has some value. <a href=" |UPDATE_PROFILE| " target="_blank" >change subscription preferences</a> How can i write it some thing like or even is this possible? if *|UPDATE_PROFILE|* IS NOT EMPTY BEGIN <a href="*|UPDATE

WooCommerce Memberships check if user (with current membership plan) is able to access the contents

孤街醉人 提交于 2019-12-06 04:41:52
Currently I am trying to check if the user has the access to certain page (based on their membership plan). Below is my code, but it seems like wc_memberships_is_user_active_member only check if the user is an active member. if( wc_memberships_is_post_content_restricted() && is_page($postid) && wc_memberships_is_user_active_member( $membership_plan ) ) { //do something } else { //do something } Thanks in advance. Lim Zhiyang I managed to do it with the code below, it check whether if the user (with current membership) is able to access the page: function can_user_access_content($user_id,$post