Search Results

Search found 2229 results on 90 pages for 'conditions'.

Page 4/90 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Rails has_many conditions

    - by user305270
    c = "(f.profile_id = #{self.id} OR f.friend_id = #{self.id})" c += AND + "(CASE WHEN f.profile_id=#{self.id} THEN f.friend_id ELSE f.profile_id END = p.id)" c += AND + "(CASE WHEN f.profile_id=#{self.id} THEN f.profile_rejected ELSE f.friend_rejected END = 1)" c += AND + "(p.banned = 0)" I need this to be used in a has_many relationship like this: has_many :removed_friends, :conditions => ??? how do i set there the self.id?, or how do i pass there the id? Then i want to use the will_paginate plugin: @profile.removed_friends.paginate(:page => 1, :per_page => 20) Thanks for your help EDIT: class Profile < ActiveRecord::Base has_many :friendships has_many :removed_friends, :class_name => 'Profile', :through => :friendships, :conditions => "(friendships.profile_id = #{self.id} OR friendships.friend_id = #{self.id})" "AND (CASE WHEN friendships.profile_id=#{self.id} THEN friendships.profile_rejected ELSE friendships.friend_rejected END = 1)" + "AND (p.banned = 0)" end class Friendship < ActiveRecord::Base belongs_to :profile belongs_to :removed_friend, :class_name => 'Profile', :foreign_key => "(CASE WHEN friendships.profile_id = #{self.id} THEN friend_id ELSE profile_id END)" end

    Read the article

  • Checking multiple conditions in Ruby (within Rails, which may not matter)

    - by Ev
    Hello rubyists and railers, I have a method which checks over a params hash to make sure that it contains certain keys, and to make sure that certain values are set within a certain range. This is for an action that responds to a POST query by an iPhone app. Anyway, this method is checking for about 10 different conditions - any of which will result in an HTTP error being returned (I'm still considering this, but possibly a 400: bad request error). My current syntax is basically this (paraphrased): def invalid_submission_params?(params) [check one] or [check two] or [check three] or [check four] etc etc end Where each of the check statements returns true if that particular parameter check results in an invalid parameter set. I call it as a before filter with params[:submission] as the argument. This seems a little ugly (all the strung together or statements). Is there a better way? I have tried using case but can't see a way to make it more elegant. Or, perhaps, is there a rails method that lets me check the incoming params hash for certain conditions before handing control off to my action method?

    Read the article

  • Problems while trying to make a query with variables in the conditions (stored procedure)

    - by pablo89
    Hi!! Im having a problem, Im trying to do a query... I remember that in the past I did something like this but today this query is returning nothing, no error, no data, just nothing... the query is something like this: SELECT field1, @variableX:=field2 FROM table WHERE (SELECT COUNT(fieldA) FROM table2 WHERE fieldB=@variableX AND fieldC=0)0 AND (SELECT COUNT(fieldA) FROM table2 WHERE fieldB=@variableX AND fieldC=4)=0; I also tried this query but it didnt work (also it gaves no error): SELECT field1, @variableX:=field2, @variableY:=(SELECT COUNT(fieldA) FROM table2 WHERE fieldB=@variableX AND fieldC=0), @variableZ:=(SELECT COUNT(fieldA) FROM table2 WHERE fieldB=@variableX AND fieldC=4) FROM table WHERE @variableY0 AND @variableZ=0; As you can see, what Im trying to do in the 1st query is use a variable in the conditions; in the 2nd query Im trying to create some variables and evaluate them in the conditions. At the end in the 2nd query the @variableY=1 AND @variableZ=0 but I dont know what the query returns an empty data What could be wrong here??? Any comment or suggest is welcome!!! thanks!!! Bye!!!

    Read the article

  • How to set 2 conditions / criterias for VLOOKUP / LOOKUP / etc in OpenOffice Calc (or Excel)

    - by MestreLion
    I have this spreadsheet that started as a silly aid for a game (Mafia Wars 2), but grew into a tricky spreadsheet question. In the game your character have 9 "slots" for weapons and armors, 1 for each "type": Light Weapon, Heavy Weapon, Body Armor, Head Armor, etc. So I made a list of all weapons and armors available in the game, 1 item per row. Example: SHOP ITEM TYPE ITEM NAME ATK DEF PRICE EQUIPPED? Marketplace Weapon Light Konrad Knife 16 5 5.500 Marketplace Weapon Light Ice Queen 19 6 8.200 Marketplace Armor Body Up Layered Polym 0 31 8.600 Marketplace Armor Body Up Full Shield 7 42 17.650 Marketplace Weapon Heavy Konrad Bullpup 53 25 24.500 Marketplace Weapon Heavy Full Moon Blow 73 12 24.500 x Marketplace Armor Body Low Knee Pads 17 26 14.200 x Marketplace Armor Body Low Army Boots 15 55 24.500 Bone Yard Weapon Light Bone Launcher 41 2 9.400 x Neon Strip Vehicle Ground Supercharged 41 34 24.500 Dead End Weapon Heavy Sharp Sickle 21 5 24.500 Dead End Armor Body Low Unholy Boots 5 36 15.000 Dead End Armor Head Hockey Mask 5 18 15.900 x Last columns is an indication of the items i have already bought and equipped (marked with "x"). What I need is a formula that, for each "slot" (item type), returns info related to the item of that kind that I am using. That would be: ITEM TYPE SHOP NAME ITEM NAME ATK DEF PRICE Weapon Light Bone Yard Bone Launcher 41 2 9.400 Weapon Heavy Marketplace Full Moon Blow 73 12 24.500 Weapon Special -- -- -- -- -- Armor Body Up -- -- -- -- -- Armor Body Low Marketplace Knee Pads 17 26 14.200 Armor Head Dead End Hockey Mask 5 18 15.900 Vehicle Ground -- -- -- -- -- Vehicle Water -- -- -- -- -- Vehicle Air -- -- -- -- -- The item types are fixed, so they can be hard coded. Each row for an item type. So, for 1st result line, it would return data from the row where both 2nd column is "Weapon Light" and last column is "x". Basically I need a LOOKUP (or VLOOKUP, or anything else) that uses 2 criteria to find a given row, the item type and the X marker. Question is: HOW? I am using OpenOffice Calc 3.2.1, but since it shares so many functions with MS Excel, answers for Excel are also fine (as long as it only uses regular formulas, no VBScript or Macros or VBA etc) Last but not least, suggestions / solutions for rearranging the data so it makes this problem easier to solve are also welcome. Thanks!

    Read the article

  • check two conditions in two different columns in excel and count the matches

    - by user1727103
    I've trying to create a Error Log to help me analyse my mistakes. So for simplicity, lets assume I have two columns "Type of Question" - with values SC,RC,CR and another column that indicates whether I got this question "right/wrong".Let's assume this is my table: Question No. | Right/Wrong | Question Type | Right | SC | Right | RC | Wrong | SC | Wrong | CR | Right | RC (Pardon my formatting skills). And I want an output table like this Type of Question | Right | Wrong | Total SC | 1 | 1 | 2 RC | 2 | 0 | 2 CR | 0 | 1 | 1 So basically what I want to do is check Column3 for SC using =COUNTIF(C1:C5,"SC"), and return the total number of SC questions, and then outta the SC , I need to find out which are Right.If I know the right and the total I can get the wrong. I have never written a macro so a formula based answer would suffice.

    Read the article

  • Question about conditions of vps host provide

    - by baobeiii
    Looking into buying a VPS from a company. In their terms of service it says: User may not: a) Use 25% or more of system resources for longer then 90 seconds. There are numerous activities that could cause such problems; these include: CGI scripts, FTP, PHP, HTTP, etc. So basically your only allowed to use a 1/4 of what your paying for? Anyone know if this is a standard restriction for most hosting providers? Seems a bit ridiculous but i don't know whats normal in the server world. And the weird thing is they only sell xen servers so why can't i use my allotted resources as no-one else can. Thanks.

    Read the article

  • Insert blank row on two conditions

    - by lost_my_wallet_in_el_segundo
    I have a spreadsheet with a large number of rows. There are two rows grouped together (for each customer). In column A, the first row has an account number. The second row should be blank. The spreadsheet has lots of customers listed where there is no second row. I need to insert a blank line to create a second row for each customer that doesn't have one. Here is the VBA script I cobbled together, but it gets a syntax error. Sub Macro1() ' ' Macro1 Macro ' For myrow = 1 To Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row If Cells(myrow, 1) <> "" and Cells(myrow+1, 1) <> "" Then Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove End Sub

    Read the article

  • Rails has_many with dinamyc :conditions

    - by Fabiano PS
    Hello! What I want is to create a Model that connects with other by a has_many in a dinamic way, without the foreing_key like this: has_many :faixas_aliquotas, :class_name => 'Fiscal::FaixaAliquota', :conditions => ["regra_fiscal = ?", ( lambda { return self.regra_fiscal } ) ] But I get the error: : SELECT * FROM "fis_faixa_aliquota" WHERE ("fis_faixa_aliquota".situacao_fiscal_id = 1 AND (regra_fiscal = E'--- !ruby/object:Proc {}')) Is my will makeable? I don't wanna black magic solution..

    Read the article

  • Rails has_many with dynamic conditions

    - by Fabiano PS
    Hello! What I want is to create a Model that connects with another using a has_many association in a dynamic way, without the foreign key like this: has_many :faixas_aliquotas, :class_name => 'Fiscal::FaixaAliquota', :conditions => ["regra_fiscal = ?", ( lambda { return self.regra_fiscal } ) ] But I get the error: : SELECT * FROM "fis_faixa_aliquota" WHERE ("fis_faixa_aliquota".situacao_fiscal_id = 1 AND (regra_fiscal = E'--- !ruby/object:Proc {}')) Is this possible?

    Read the article

  • initial conditions in coupled systems

    - by Alireza
    how should i write the initial conditions and solve two coupled differential equation? for ex. like: s1 := diff(n[D](t), t) = a-b*n[D](t)^2-c*n[D](t)-e*n[D](t)*n[T](t) s2 := diff(n[T](t), t) = b*n[D](t)^2-c*n[D](t)-e*n[D](t)*n[T](t) dsolve({s1, s2});

    Read the article

  • Display numbers from 1 to 100 without loops or conditions

    - by Harsha
    Is there a way to print numbers from 1 to 100 without using any loops or conditions like "if"? We can easily do using recursion but that again has an if condition. Is there a way to do without using "if" as well? Also no repetitive print statements,or a single print statement containing all the numbers from 1 to 100. A solution in Java is preferable.

    Read the article

  • activerecord search conditions - looking for null or false

    - by Daniel
    When doing a search in active record I'm looking for record's that do not have an archived bit set to true. Some of the archived bits are null (which are not archived) others have archived set to false. Obviously, Project.all(:conditions => {:archived => false}) misses the projects with the archived bits with null values. How can all non-archived projects be selected wtih active record?

    Read the article

  • [jQuery] Form Conditions

    - by Nimbuz
    I have a form that has several conditional form elements. For example If x is selected in dropdown a, show/hide textfield a etc.. Is there a plugin for it or do I have to write those conditions manually? Thanks for your help!

    Read the article

  • Ninject Contextual Binding: Where do I get Ninject.Conditions.dll

    - by Twisted
    I've read about ninjects contextual binding here : http://ninject.codeplex.com/wikipage?title=Contextual%20Binding and am trying to get it working in my project. The docs state that I need to add a reference to Ninject.Conditions.Dll which I do not have. Does anybody know where to get this? I've tried over at github : https://github.com/ninject/ninject I used the download link to get the 2.0.1.0 sources and managed to build them but no dll. I found a similar question here : Where can I find ninject.web.mvc.dll? and an answer with a link to a build server. I followed the link and I get a login request for team city. I don't have an account.

    Read the article

  • Conditions on the DetailsView

    - by jpabluz
    What is the best way of implementing conditions (requiring fields based in other fields) in a DetailsView? I have this: protected override ICollection CreateFieldSet(object dataItem, bool useDataSource) { var country = new BoundField(); country.DataField = "Country"; country.ReadOnly = ViewState["DifferentAddress"] != null; } I set the ViewState["DifferentAddress"] later, but since the change happens after the controls are created I lost the current state and get the old state. Which is the desired way of doing this? I am in the right path - or should I use another class to do this?

    Read the article

  • Multiple aggregate functions in one SQL query from the same table using different conditions

    - by Eric Ness
    I'm working on creating a SQL query that will pull records from a table based on the value of two aggregate functions. These aggregate functions are pulling data from the same table, but with different filter conditions. The problem that I run into is that the results of the SUMs are much larger than if I only include one SUM function. I know that I can create this query using temp tables, but I'm just wondering if there is an elegant solution that requires only a single query. I've created a simplified version to demonstrate the issue. Here are the table structures: EMPLOYEE TABLE EMPID 1 2 3 ABSENCE TABLE EMPID DATE HOURS_ABSENT 1 6/1/2009 3 1 9/1/2009 1 2 3/1/2010 2 And here is the query: SELECT E.EMPID ,SUM(ATOTAL.HOURS_ABSENT) AS ABSENT_TOTAL ,SUM(AYEAR.HOURS_ABSENT) AS ABSENT_YEAR FROM EMPLOYEE E INNER JOIN ABSENCE ATOTAL ON ATOTAL.EMPID = E.EMPID INNER JOIN ABSENCE AYEAR ON AYEAR.EMPID = E.EMPID WHERE AYEAR.DATE > '1/1/2010' GROUP BY E.EMPID HAVING SUM(ATOTAL.HOURS_ABSENT) > 10 OR SUM(AYEAR.HOURS_ABSENT) > 3 Any insight would be greatly appreciated.

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >