Questions tagged [has-and-belongs-to-many]

A has_many :through association set up a many-to-many connection with another model.

In Ruby on Rails, a has_many :through association is often used to set up a many-to-many connection with another model. This association indicates that the declaring model can be matched with zero or more instances of another model by proceeding through a third model.

1372 questions
0
votes
1 answer

Save data with Belong to many cakehp 3.x

I have two tables articles and tags and third association table articles_tagsnow i want to save data in articles_tags when create new article and user select multiple tags from drop down my controller code is below public function add() { …
Deepak Goyal
  • 1,186
  • 2
  • 13
  • 26
0
votes
1 answer

What's Going Wrong With My CakePHP HABTM Query?

I have a table called Landmarks and a table called Categories with a HABTM relationship to each other. I am trying to retrieve all the categories for a specific Landmark with the following code: $this->set('selected_categories',…
thesunneversets
  • 2,560
  • 3
  • 28
  • 46
0
votes
2 answers

Cake PHP 3.4 - how to add 2 inner joins on the same query?

Cake PHP 3.4 running on MAMP. I have the following scenario: SQL tables TABLE `Ingredients` ( `id` int(11) NOT NULL, `name` varchar(255) NOT NULL, `category_id` int(11) NOT NULL, `measure_id` int(11) NOT NULL ) ENGINE=InnoDB DEFAULT…
Tzi
  • 35
  • 1
  • 4
0
votes
1 answer

Saving hasOne with HABTM in CakePHP

This problem occurred when I added a hasOne relationship to one of the habtm models. categories_posts now do not save anything in the database. I did before. Right now, the form I have is this: Form->create('Post'); echo…
Teej
  • 12,764
  • 9
  • 72
  • 93
0
votes
2 answers

Messaging system in Rails

I want to set up a whitelist messaging system in rails where users can select which other users they want to send the comment. The message could be visible to everyone or just one person. How would I set this up and what would the message form look…
maletor
  • 7,072
  • 7
  • 42
  • 63
0
votes
1 answer

Rails habtm query based on a condition

I have following associations: class ConferenceSession < ActiveRecord::Base has_many :conference_sessions end class ConferenceSession < ActiveRecord::Base belongs_to :conference has_and_belongs_to_many :users end class User <…
0
votes
1 answer

Rails HABTM has_many destroy error

I have a has_and_belongs_to_many using has_many between users and workspaces. user.rb class User < ActiveRecord::Base has_many :user_workspaces, dependent: :destroy has_many :workspaces, through: :user_workspaces before_destroy…
0
votes
1 answer

Containable won't filter 2nd level model with HABTM & hasMany

What I have: "A" HABTM "C" HABTM "A" through join table "B" "A" hasMany "B" belongsTo "A" "C" is ordered by a "B" field What I want: // result: [0] => array( A => array( /* single model's fields I still need*/ ), C => array( [0]…
Myer
  • 3,670
  • 2
  • 39
  • 51
0
votes
1 answer

How to data fetch by using has many through in django?

I am learning django. I have a simple model named customer. Here is my model: class Year(models.Model): year = models.CharField(max_length=255) created_at = models.DateTimeField(auto_now=False, auto_now_add=True) updated_at =…
HM Tanbir
  • 990
  • 12
  • 30
0
votes
1 answer

multiple has_many through with the same model rails

I am trying to set up the model structure that has a User model Project model along with two join tables setup as has_many through to manage two specific aspects of the Project, ProjectManagers and ProjectMembers. I can setup two…
0
votes
0 answers

Cake php 3 | belongsToMany error while saving

I have below 3 tables sub-ambiences id | other fields restaurant-branches id | other fields restaurant_branches_sub_ambiences id | restaurant_branch_id | sub_ambience_id I am adding the restaurant_branches and want to save associations in…
0
votes
2 answers

Add Quantity to a Recipe habtm Ingredients Relation

I wanted to build a basic cookbook. With a Recipes habtm Ingredients Relation. My first attempt was like this. class Recipe < ActiveRecord::Base # title, description has_many :recipe_ingredients end class Ingredient < ActiveRecord::Base #…
0
votes
2 answers

In a "has-a" class relationship does the contained class have to be implemented inside the class . .

In a "has-a" class relationship does the contained class have to be implemented inside the class that contains it or can it be written entirely separately in a different file? For example: let's say: class Pen { public: . . . …
0
votes
0 answers

Creating new model object that uses a join table to another model object?

Trying to create a Sale that has a join table to Events and establish a relationship when it is created from a dropdown list of all available events. <%= form_for(@deal) do |f| %> <% if @deal.errors.any? %>
user6107987
0
votes
1 answer

Ruby on rails simple relationship has_and_belongs_to_many

I have a simple rails app where I am trying to establish the relationship between two models. I have a plan model and a subscription model. A subscription will only ever have 1 plan but plans can belong to many subscriptions. As there is no…
Tom Pinchen
  • 2,467
  • 7
  • 33
  • 53