has-one

Rails4 ActiveRecord has_one :conditions key removed

我与影子孤独终老i 提交于 2021-01-28 12:10:40
问题 I am converting a RoR3.2 app to v4.2. In some models we have this construct: # A correspondent can have only one currently active client role or # it may have none. has_one :active_client, :class_name => 'Client', :conditions => IsActiveRow I am getting this error: Unknown key: :conditions. Valid keys are: :class_name, :class, :foreign_key, :validate, :autosave, :dependent, :primary_key, :inverse_of, :required, :as, :foreign_type (ActionView::Template::Error) Which is raised here: /home

How to get devise to work with accepts_nested_attributes_for in a has one relationship?

﹥>﹥吖頭↗ 提交于 2020-01-23 10:45:08
问题 I am trying to get my user form to also allow the user to fill out their company profile at the same time via form_for. For some reason it is not showing the company fields. Here is my code for the controller and layouts. class User < ActiveRecord::Base attr_accessible :company_attributes has_one :company accepts_nested_attributes_for :company end class Company < ActiveRecord::Base belongs_to :user # Validation validates :name, :presence => true end <%= f.fields_for :company do |company_form|

has_many conditions or proc on foreign key

耗尽温柔 提交于 2020-01-14 18:13:51
问题 I have a has_many association between two models using a date as both the foreign and primary key for each model. It works perfectly one way but not the other. Works has_one :quiz_log, :primary_key => :start_at, :foreign_key => :start_at Doesn't work has_many :event_logs, :primary_key => :start_at, :foreign_key => :start_at The reason being (i think) because the start_at on QuizLog is a date and the start_at on EventLog is a datetime . So it returns nil trying to match the exact datetime on a

has_many conditions or proc on foreign key

眉间皱痕 提交于 2020-01-14 18:08:43
问题 I have a has_many association between two models using a date as both the foreign and primary key for each model. It works perfectly one way but not the other. Works has_one :quiz_log, :primary_key => :start_at, :foreign_key => :start_at Doesn't work has_many :event_logs, :primary_key => :start_at, :foreign_key => :start_at The reason being (i think) because the start_at on QuizLog is a date and the start_at on EventLog is a datetime . So it returns nil trying to match the exact datetime on a

rails has_one relationship causing problems - also white screen

孤街浪徒 提交于 2020-01-14 05:45:07
问题 I have two models: Schedule and Project. Schedule belongs_To Project and Project has_one schedule. There are several problems, but i think they all have the same cause. Here is the code for the schedules#create controller: def create @schedule = Schedule.new(schedule_params) @schedule.project = Project.find(params[:project_id]) if @schedule.project.student_id == current_user.id if @schedule.save && @schedule.freelancer_accepts flash[:notice] = "Successfully created schedule." redirect_to

LoopbackJS / AngularJS find with relation hasOne include separated attribute

三世轮回 提交于 2020-01-06 19:38:12
问题 i'm making a find query in angularjs using loopbackapi , in mysql db. I have a model with a hasOne relation with another one. Empresa hasOne Operadora When i do a find in Empresa using include args, it brings me Operadora attributes, but it include the attributes inside Empresa, but i would like to have it separated. I tested using those examples: Empresa.findOne({ include: {"relation" : 'Operadora', 'as': 'Operadora'} Empresa.findOne({ include: {model: 'Operadora', 'as': 'Operadora'} Empresa

where condition with HasOne laravel

霸气de小男生 提交于 2020-01-03 19:57:32
问题 In login model I have implement relation with picture table function picture () { return $this->hasOne('App\Picture'); } Now I want data where Picture.picture_status = 1 and User.user_status = 1 Login::with('picture')->where('picture_status', 1)->where('user_status',1); but where condition is not working with picture table, how can i implement and condition on both table 回答1: This should do it: Login::with(['picture' => function ($query) { $query->where('picture_status', 1)->where('user

Cannot get nested form with a has_one association to work

坚强是说给别人听的谎言 提交于 2020-01-03 17:36:39
问题 I have these models: class User < ActiveRecord::Base has_one :city accepts_nested_attributes_for :city end class City < ActiveRecord::Base belongs_to :user end This controller action: def create @user = User.new(params[:user]) respond_to do |format| if @user.save format.html { redirect_to(@user, :notice => 'User was successfully created.') } format.xml { render :xml => @user, :status => :created, :location => @user } else format.html { render :action => "new" } format.xml { render :xml =>

Cannot get nested form with a has_one association to work

风格不统一 提交于 2020-01-03 17:36:13
问题 I have these models: class User < ActiveRecord::Base has_one :city accepts_nested_attributes_for :city end class City < ActiveRecord::Base belongs_to :user end This controller action: def create @user = User.new(params[:user]) respond_to do |format| if @user.save format.html { redirect_to(@user, :notice => 'User was successfully created.') } format.xml { render :xml => @user, :status => :created, :location => @user } else format.html { render :action => "new" } format.xml { render :xml =>

hasMany reduced to hasOne in CakePHP

廉价感情. 提交于 2020-01-02 10:18:13
问题 Basically I have following models in CakePHP: User(id, username) Photo(id, user_id, path) I have set up following relation: User hasMany Photo. On one screen, I would like to list users, and show random photo next to each user. I tried setting up following relation: User hasOne SamplePhoto (where SamplePhoto is just Photo model) but when user has two photos for instance, he is listed twice on the list. basically my question is: can you reduce hasMany relation to hasOne, without adding any