in Education by
I have following Comments-on-Models design (source: http://railscasts.com/episodes/154-polymorphic-association): class Comment belongs_to :commentable, :polymorphic => true end class Post has_many :comments, as => :commentable end class Message has_many :comments, :as => :commentable end etc... How can I select all records from 'comments' table, so that each record has non-dead commentable (dead means original fx Post was deleted) by scope-based query? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Since commentable not exists in case of dead-commentable, you can do something like this: class Comment belongs_to :commentable, :polymorphic => true scope :non_dead_commentable, where('commentable IS NOT NULL') end In rails 4 you can do: scope :non_dead_commentable, where.not(:commentable => nil) And then: Comment.non_dead_commentable

Related questions

0 votes
    I have this example code which raises a "Duplicate Expection". Instead, I want just to skip if a duplicate exists. (1..10).each do |page| group.products...
asked May 26, 2022 in Education by JackTerrance
0 votes
    having this code block of an example rails model class: class Block < ActiveRecord::Base has_many :bricks, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    Does pattern association involves non linear units in feedforward neural network? (a) yes (b) no I had been ... Neural Networks of Neural Networks Please answer the above question....
asked Sep 4, 2022 in Education by JackTerrance
0 votes
    Hi I am having problems with relation and database design. There are three tables called 'articles' , ' ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    ___________________ is the method used to locate all the DNS-servers and their associated records for an organization. (a ... questions and answers pdf, mcq on Cyber Security pdf,...
asked Nov 4, 2021 in Education by JackTerrance
0 votes
    __________ scheme that records only information about dirty pages and associated information and does not even require ... topic in section Recovery System of Database Management...
asked Oct 10, 2021 in Education by JackTerrance
0 votes
    Here, the context of polymorphic is expecting 'Derived' from 'Base&. Given class P { }; class Q : ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 16, 2022 in Education by JackTerrance
0 votes
    A coin is tossed. Find the total number of elementary events and also the total number of events associated with the random experiment. Select the correct answer from above options...
asked Nov 22, 2021 in Education by JackTerrance
0 votes
    If A and B be mutually exclusive events associated with a random experiment such that P (A) = 0.4 and P (B) = 0.5 ... (iv) P(A ∩ bar B) Select the correct answer from above options...
asked Nov 22, 2021 in Education by JackTerrance
0 votes
    If A and B are two events associated with a random experiment such that P (A) = 0.3, P (B) = 0.4 and P (A ∪ B) = 0.5, find P (A ∩ B). Select the correct answer from above options...
asked Nov 22, 2021 in Education by JackTerrance
0 votes
    If A and B are two events associated with a random experiment such that P (A) = 0.5, P (B) = 0.3 and P (A ∩ B) = 0.2, find P (A ∪ B). Select the correct answer from above options...
asked Nov 22, 2021 in Education by JackTerrance
0 votes
    If A and B are two events associated with a random experiment such that P (A ∪ B) = 0.8, P (A ∩ B) = 0.3 and P (A′) = 0.5, find P(B). Select the correct answer from above options...
asked Nov 22, 2021 in Education by JackTerrance
0 votes
    If A and B are two events associated with a random experiment for which P(A) = 0.60, P(A or B) = 0.85 and P(A and B) = 0.42, find P(B). Select the correct answer from above options...
asked Nov 22, 2021 in Education by JackTerrance
0 votes
    Let A and B be two events associated with a random experiment for which P(A) = 0.4, P(B) = 0.5 and P(A or B) = 0.6. Find P(A and B). Select the correct answer from above options...
asked Nov 22, 2021 in Education by JackTerrance
0 votes
    If A and B are two events associated with a random experiment such that P(A) = 0.25, P(B) = 0.4 and P(A or B) ... ) (ii) P(A and bar B) Select the correct answer from above options...
asked Nov 22, 2021 in Education by JackTerrance
...