M
M
Max Pavlov2011-08-11 15:25:29
Ruby on Rails
Max Pavlov, 2011-08-11 15:25:29

Electoral association in RoR

There are 2 models. It is necessary to make it so that the many-to-one association of the second model with the first is set only when a certain value is found in the field of the first model,

can this be implemented?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
bsboris, 2011-08-11
@minduser

If I understand the question correctly, then it is done like this:

class Customer < ActiveRecord::Base
  has_many :confirmed_orders, :class_name => "Order", :conditions => "confirmed = 1"
end

S
sl_bug, 2011-08-11
@sl_bug

class User
has_many :posts
end
class Post
belongs_to :user
end
@user.posts #=> [] пусто. еще ниче не добавили. ну и не будем добавлять если флаг какой-то стоит. условия выполнены?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question