has-and-belongs-to-many

Sequelize belongsToMany additional attributes in join table

最后都变了- 提交于 2019-12-06 15:05:22
I'm having problem with an additional attribute in the join table of the belongsToMany relation. In the set or add method this attribute is not being passed to mysql. I'm following the documentation pass as "through" the attribute within the set method, but it is not working. Would anyone know what could be wrong since following the documentation is not working? Note: The registration and update of the join is correct, only the additional attribute that is not being passed to the table. Functionality Model: export default function(sequelize, DataTypes) { const Functionality = sequelize.define(

Creating multiple records in a HABTM relationship using a collection_select - Rails

半城伤御伤魂 提交于 2019-12-06 14:41:47
I have a has_and_belongs_to_many relationship between workouts and groups. I have a collection_select in groups that I'm using to add workouts to groups. The problem is that I can only change the one record in the HABTM table, so I can only add one record, then edit that record. How do I add additional records? Any ideas? Here is some code: show.html.erb: <%= form_for(@group) do |f| %> <%= f.collection_select 'workout_ids', Workout.all, :id, :name, { :include_blank => ""} %> <%= f.submit %> <% end %> . class Workout < ActiveRecord::Base attr_accessible :name, :exercises_attributes, :workout

Rails3 + Typus: display habtm relationship as checkboxes

别来无恙 提交于 2019-12-06 14:26:59
I'm managing my admin backend with Typus I want to add a field with a checkbox for each category. I used this code: Post: fields: default: name, description, user, categories list: name, description, user, categories form: name, description, user, categories relationships: categories But the result is a textfield with a [] inside: how do I solve this? Is there a native way or must I override the field template? To show the the checkbox for the fields you can use the existing template of the Typus Post: fields: default: name, description, user, categories list: name, description, user,

CakePHP defining additional fields in HABTM/ManyToMany relationship?

◇◆丶佛笑我妖孽 提交于 2019-12-06 12:33:56
Basically I would like to recreate this in CakePHP: Many to many relationships with additional data on the relationship or in other words, my intermediary table to have extra fields defining the type of relationship. How do I set this up in CakePHP? You can use as example: model company: id name person_id model person: id name model company_person: company_id person_id position thanx if you want to have additional data in HABTM, use 2 hasMany relationships instead. So if A HABTM B, then set it up as: A hasMany A_B, B hasMany A_B, A_B belongsTo A, A_B belongsTo B. AFAIK, Cake support for HABTM

CakePHP 3: CounterCache with BelongsToMany

自作多情 提交于 2019-12-06 11:52:17
I have a BelongsToMany association, my tables are PostsTable , TagsTable and PostsTagsTable . As explained here in the CakePHP book (associations) , I have this fields: tags.id, tags.tag, tags.post_count posts_tags.id, posts_tags.tag_id, posts_tags.post_id Everything works correctly for now. So, as you can understand, now I want to use the tags.post_count field with CounterCache . I followed the CakePHP book , but I suppose this is a special case, in fact it doesn't work by simply adding the behavior to the PostsTable . Can you help me? Thanks. From CakePHP Book The CounterCache behavior works

Making HABTM relationships unique in CakePHP

♀尐吖头ヾ 提交于 2019-12-06 08:53:11
I have two models, called Book and Tag, which are in a HABTM relationship. I want a couple (book, tag) to be saved only once. In my models I have var $hasAndBelongsToMany = array( 'Tag' => array( 'className' => 'Tag', 'joinTable' => 'books_tags', 'foreignKey' => 'book_id', 'associationForeignKey' => 'tag_id', 'unique' => true ) ); and viceversa, but the Unique flag does not help me; I can still save two times the same couple. How do I do this in CakePHP? Should I declare the couple (book, tag) unique in the database directly, or will this make CakePHP go nuts? Is there a Cakey way to handle

Paginate results filtered by condition on associated model (HABTM) using Containable

别等时光非礼了梦想. 提交于 2019-12-06 05:40:59
I need to paginate list of Product s belonging to specific Category (HABTM association). In my Product model I have var $actsAs = array('Containable'); var $hasAndBelongsToMany = array( 'Category' => array( 'joinTable' => 'products_categories' ) ); And in ProductsController $this->paginate = array( 'limit' => 20, 'order' => array('Product.name' => 'ASC'), 'contain' => array( 'Category' => array( 'conditions' => array( 'Category.id' => 3 ) ) ) ); $this->set('products', $this->paginate()); However, resulting SQL looks like this: SELECT COUNT(*) AS `count` FROM `products` AS `Product` WHERE 1 = 1

CakePHP HABTM - I don't understand it

主宰稳场 提交于 2019-12-06 05:10:52
Asked before but still in the dark. cakePHP HABTM, am I getting it all wrong? Will try again: I have two tables: stores and managers I want to create a new table, managers_stores and use it to keep a complete list of mangers for each store. I understood that each save() action that will provide the full record data (as I intend to do) will result in the deletion of the table rows and only the new record will be kept.. This is an UNDESIRED behavior for my needs. So, how should I manage the HABTM info of my application and what's the idea behind deleting data that I saved?! thanks save() will

How do I query data in CakePHP using HABTM relationships?

限于喜欢 提交于 2019-12-05 23:49:15
问题 I'm working on a CakePHP 1.2 application. I have a model "User" defined with a few HABTM relationships with other tables through a join table. I'm now tasked with finding User information based on the data stored in one of these HABTM tables. Unfortunately, when the query executes, my condition is rejected with an error about a missing table. Upon inspection it seems that CakePHP is not including any of the HABTM tables in the select statement. My User HABTM relationship is as follows: var

Rails RESTful delete in nested resources

折月煮酒 提交于 2019-12-05 22:32:15
Okay, so here's an example scenario. There is a student resource resources :students , and students has and belongs to many collections: resources :clubs , resources :majors , etc. So we can set up our routes easily enough... resources :clubs do resources :students end resources :majors do resources :students end resources :students do resources :clubs resources :majors end which generates us a bunch of standard RESTful routes /clubs /clubs/:id /clubs/:club_id/students /clubs/:club_id/students/:id /majors /majors/:id /majors/:major_id/students /majors/:major_id/students/:id /students /students