Ember Data works with all its IDs as strings. Changing your check to === '1' should get this going for you. import Ember from 'ember'; export default Ember.Route.extend({ model: function() { return Ember.RSVP.hash({ layouts: this.store.filter('layout', { account_id: 1 }, function(layout) { console.log(layout.get('account').content.id); return layout.get('account').content.id === '1'; }) }); } });...
ruby-on-rails,postgresql,foreign-keys,belongs-to
I don't really use has_many and belongs_to with different foreign keys than the standard, but according to the docs I would do this: class VideoCollection < Collection has_many :video_works, foreign_key: "folder_id" end class VideoWork < Work belongs_to :folder, class_name: "VideoCollection", foreign_key: "folder_id" end Your Pg error says that the association...
ruby-on-rails,scope,has-many,belongs-to
scope :by_a ->(aa) { joins(:c).where(c_id: C.joins(:b).where(b_id: B.joins(:a).where(a_id: aa.id))) } ...
ruby-on-rails,ruby,model,html-select,belongs-to
Either you add a method to your employee that you can call, like: class Employee < ActiveRecord::Base ... def entity_name self.entity.name end end and then: select_tag "employee_compensation_benefits_selection", options_from_collection_for_select(@employees, "id", "entity_name", "1") or you can use a lambda instead of adding a method: select_tag "employee_compensation_benefits_selection", options_from_collection_for_select(@employees, "id", lambda { |employee| employee.entity.name...
ruby-on-rails,controller,associations,belongs-to,button-to
You are on the right track, you have created an association, now you just need to reference the project in the create method like this : def new @project = Project.find params[:project_id] @issue = @project.issues.build end def create @project = Project.find(params[:project_id]) @issue = @project.issues.build(issue_params) ## rest of code end then...
ruby-on-rails,rails-activerecord,belongs-to,has-one
Rails Guides provides an explanation as to why you're experiencing the problem. Essentially, when you declare a belongs_to relationship, the foreign key appears on the table for the class declaring it. When you declare a has_one relationship, the foreign key is on the table for the class in the declaration....
php,sql,laravel,eloquent,belongs-to
Well, this error occurred because I had '.' in place of '->'. I couldn't figure out why it was always throwing the exact same error regardless if I did $this.belongsTo('App\User'); or $this.hasMany('App\User'); or even $this.thecakeisalie('App\User'); until I sat staring at the text between my many models yet again. Then, lo...
ruby-on-rails,ruby,parent-child,belongs-to
I discovered the answer to this a few days ago, but forgot to wrap this up. I was thinking about the whole architecture of this wrong. Upon talking to the senior devs around my office we came to the conclusion that in most standard cases, you will want to create...
ruby-on-rails,ruby,activeadmin,belongs-to
ActiveAdmin allows you to use nested resources with a belongs_to method, as you clearly already know: ActiveAdmin.register Project do end ActiveAdmin.register Ticket do belongs_to :project end ActiveAdmin.register Milestone do belongs_to :project end Because Inherited Resources' firepower can't be aware of every custom implementation in the book, you may have to...
If you want to get the user who has the micropost, you should use micropost.user. For example: @microposts.first.user will return the user of @microposts's first record.
ruby-on-rails,ruby,activerecord,belongs-to
The Reception model definitely doesn't belong_to the Attendee model. The relationship between Receptions and Attendees will be either a has_many, or a 'has_many through' relationship. It's worth reading through the full doco on assocations. You mention: The idea is that a user will be able to go to the wedding's...
php,mysql,join,phalcon,belongs-to
$queryBuilder = $this->getDI()->getModelsManager() ->createBuilder() ->columns(['r.id','r.name', 'r.type_id', 'rt.type']) ->addFrom('Robot', 'r') ->leftJoin('RobotTypes', 'rt.id = r.type_id', 'rt'); $resultSet = $queryBuilder->getQuery()->execute();//->toArray(); //optional If you call by name all columns you need, you should be able to retrieve full result w/o multiquerying DB for types separately. It's still not a PHQL, it also does not...
ruby-on-rails,associations,has-many,belongs-to
If I am reading this right, then all you need to do is add another has_many :key_contacts relation to your SalesOpportunity model (and belongs_to :sales_opportunity in your KeyContacts model). Then relate all contacts belonging to a specific sales opportunity.
ruby-on-rails,ruby-on-rails-4,database-migration,has-many,belongs-to
Try like that:- somecar = CarBrand.where(:brand => 'Toyota') somecar.first.car_models As CarBrand.where(:brand => 'Toyota') returns an array. OR Try like that:- somecar = CarBrand.find_by brand: 'Toyota' somecar.car_models CarBrand.find_by brand: 'Toyota' will fetch first matching record....
ruby-on-rails,json,belongs-to,rails-api
I am pretty sure your problem is, that the database field for the foreign key and the associated model are having the same name. The database field is made available as a member method called 'tourn' in the model by ActiveRecord and this obviously collides with your belongs_to definition which...
php,cakephp,model,has-many,belongs-to
The problem is that you are fetching only id field in: $cs=$this->CkMmUsersKta->find("all",array('fields'=>array('CkMmUsersKta.id'))); You should specify the name field also. $cs=$this->CkMmUsersKta->find("all",array('fields'=>array('CkMmUsersKta.id','CkSetupUser.user_name')));...
php,pdo,parent,belongs-to,cakephp-3.0
This should work out of the box, the joined in tables should be aliased properly as Registars and Parents, and for sure this worked until recently, so yes, this is a bug, possibly related to https://github.com/cakephp/cakephp/pull/5836 Please report this as an issue over at GitHub. Udate Actually it seems that...
Well this is very much doable, its just that your approach is wrong here. belongsTo is used in a way when an entity must and must be mapped with some other entity. There is nothing like either of them. What you can do is 1. create an Abstract Domain `Book`...
ruby-on-rails,foreign-keys,belongs-to
The SQL generated is using products.id instead of products.symbol because you didn't tell it that the association should use symbol as the primary key instead of the default of id. So, in your Position class just add primary_key: :symbol to the belongs_to and I think that'll do it.
ruby-on-rails,ruby,relationship,models,belongs-to
I would do a model relation like this: user.rb has_many :reviews product.rb has_many :reviews reviews.rb belongs_to :user belongs_to :product # This does the magic for the multiple validation validates_uniqueness_of :user_id, :scope => :product_id, :message=>"You can't review a product more than once", on: 'create' As you can see, i will let...
laravel,eloquent,relation,belongs-to
The idea here is to write a function which would check if a relationship is loaded and return that relationship, otherwise it will return the belongsToMany. This would go in your Report class. This is also for Laravel 5. If you have 4, just remove the namespaces from the model...
mysql,cakephp,has-many,belongs-to
You might want to use find('threaded'). You can also look into the tree behavior.
ruby-on-rails,override,setter,belongs-to
This would be better written as a callback. You can use a before_save callback to check for a parent_task and if it is set, clear groups_belonging_to: class Task < ActiveRecord::Base belongs_to :parent_task, class_name: 'Task', foreign_key: 'parent_task_id' before_save :clear_groups if: :parent_task def clear_groups self.groups_belonging_to = [] end end ...
mysql,database,laravel,relational-database,belongs-to
You can't name the relationship the same as the name of your foreign key column! Changing either one should work, however I suggest you change the foreign key columns to author_id. Then you also don't need to specify the foreign key column in your relation since you're using the conventional...
ruby-on-rails,nested-attributes,belongs-to
As I wrote in the comments, there's two ways of doing this. The first way is to add a hidden field in your subform to set the current user: = simple_nested_form_for(@issue) do |f| = f.input :title = f.fields_for(:comments) do |cf| = cf.input(:content) = cf.hidden(:user, current_user) = f.submit If you do...
ruby-on-rails,ruby,associations,has-many,belongs-to
You are getting undefined method 'city' for nil:NilClass in below code: <% @sportists.each do |s| %> <%= s.name %> <%= s.surname %> <%= s.trainer.city %> <% end %> which means that there is a sportists record which doesn't have trainer associated to it. So, for that particular sportlist record s.trainer...
ruby-on-rails,devise,user,belongs-to
It will stay null because you are not using it in the timesheetsController, your create action should be like this : def create @timesheet = current_user.timesheets.build(timesheet_params) redirect_to new_timesheet_path end You have to use that build method to reference the current_user, so the timesheet will have the current_user in the user_id...
ruby-on-rails,json,rest,has-many,belongs-to
You want nested resources in your routes: resources :stores do resources :products end So you have those routes: GET /stores/:id GET/POST /stores/:store_id/products PUT/DELETE /stores/:store_id/products/:id You'll may also want shallow routes, to avoid deeply nested resources: resources :stores, shallow:true do resources :products end So you have those routes: GET /stores/:id GET/POST...
join,laravel-4,relationship,belongs-to
You are creating an intermediate table when you're using the OneToMany relationship. You only have to do so when creating a ManyToMany relationship. Remove the order_contact table, and add a column "contract_id" on your orders table (you can optionally make it nullable, so an order doesn't have to have a...
ruby-on-rails,ruby,stripe-payments,belongs-to
Try adding the inverse relationships: #Plan has_many :teams, inverse_of: :plan #Team belongs_to :plan, inverse_of: teams The inverse relationships help ensure that save works when you save subobjects. Try looking at the id of each item before and after save: p "team_plan.id:#{team_plan.id}, team.plan.id: #{team.plan.id}" team.plan = team_plan p "team_plan.id:#{team_plan.id}, team.plan.id:#{team.plan.id}" team.save!...