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

CakePHP 2.1 pagination for habtm

I am using cakephp 2.1 and developing an application, which contain the following table structures. 1. people(id, name) 2. movies(id, name) and 'people' habtm movies by tables as follows. 1. castsmovie(id, person_id, movie_id) 2. directorsmovie(id,…
Sanganabasu
  • 943
  • 7
  • 21
  • 39
0
votes
2 answers

Using link_to to add object into HABTM relation table

In my application I have List objects and Problem objects, Lists are made up of Problems and problems can belong to many lists. I am using HABTM on both classes and I've created their join table like so: class AddTableListsProblems <…
0
votes
1 answer

HABTM with Pagination

At first take a look at the following model structure: Model Building: id name Model BuildingRange: id building_id postalcode Ok, so BuildingRange $belongsTo Building and Building $hasMany BuildingRange. Should be clear til' here. Now let…
androidavid
  • 1,258
  • 1
  • 11
  • 20
0
votes
1 answer

Rails contact form using new HABTM relationship and unregistered users

I'm new to Rails and I'm attempting to do the following, but I have a feeling I'm not doing it securely: A visitor to my site can see profile pages for users and contact them without registering. There is a has_and_belongs_to_many relationship…
crix
  • 487
  • 1
  • 4
  • 7
0
votes
2 answers

Can implement a has_and_belongs_to_many association

I'm a bit confused about a HABTM association with rails 3.2.11. I have an Image model: class Image < ActiveRecord::Base attr_accessible :description, :name, :image, :article_ids has_and_belongs_to_many :articles end And an article model: class…
user929062
  • 807
  • 4
  • 12
  • 33
0
votes
2 answers

Displaying tag names rather than IDs using the form helper

In one of my forms I have a text input for a posts tags. At the moment, Cake is returning the tag id into this field rather than the name of the tag. I want to change it to show the name of the tag. The posts controller is getting a result like…
James Dawson
  • 5,309
  • 20
  • 72
  • 126
0
votes
0 answers

has_many users and events... Rails 3.2

I've looked and looked... it just doesn't make sense to me yet. I don't know when to use has_and_belongs_to_many vs has_many through: So, calendaring. A user creates an event. Some people that are invited can view the event (through a…
Dudo
  • 4,002
  • 8
  • 32
  • 57
0
votes
1 answer

Rails: sortable has_and_belongs_to_many relationships

Given this relationship: class Doc < ActiveRecord::Base has_and_belongs_to_many :articles end and class Article < ActiveRecord::Base has_and_belongs_to_many :docs end How would you approach sorting the articles in the Doc with jQuery UI? I…
t56k
  • 6,769
  • 9
  • 52
  • 115
0
votes
1 answer

Saving post tags using a HABTM relationship

I have a Post model and Tag model which are both set up correctly with a HABTM relationship. I also have a table in my database called posts_tags which is named correctly as per the naming conventions. However, I can't for the life of me work out…
James Dawson
  • 5,309
  • 20
  • 72
  • 126
0
votes
1 answer

has_and_belongs_to_many to the same model in rails 3

I'm trying to make friends and enemies connections with has_and_belongs_to_many, therefore I created the following: create_table :people do |t| t.string :name end create_table "relations", :id => false do |t| t.integer…
sudo
  • 1,581
  • 1
  • 10
  • 11
0
votes
1 answer

Cant get answer_id into answers_results

Ive got 3 models. Question, Answer and Result. Got a middle model answers_results with an answer_id and a result_id. The questions and answers are already in the database, so when someone starts a new survey it needs to save a result_id and…
0
votes
1 answer

CakePHP HABTM recursive issue

To explain the issue I'm having, I'll use an example. Let's say that I'm building a system where students can sign up for an afterschool class, but an administrator has to approve the sign-up in order for it to be valid. So I have these…
Nick
  • 8,049
  • 18
  • 63
  • 107
0
votes
2 answers

CakePHP and HABTM insert/save doesn't work

I'm stuck in Cakephp insert, here is what I have -Order HABTM Address -Address model Here is my association in Address model : public $hasAndBelongsToMany = array( 'Address' => array( 'className' => 'Address', 'joinTable' =>…
azerto00
  • 1,001
  • 6
  • 18
0
votes
1 answer

Query on Multiple Associations with CakePHP Models

I'm very new to CakePHP (started last night) and I'm having an issue with queries. The way my model works is this: Classgroups << hasAndBelongsTo >> Users << hasAndBelongsTo >> PermissionsGroups Basically a Classgroup is made up of a load of users…
carlmango11
  • 525
  • 5
  • 19
0
votes
1 answer

Not able to save Employee model

I'm a RoR newbie. I'm not able to create a new employee with assigned role. From the serverlog below I sort of figured that the record is not getting saved because "role_ids" is blank but I cannot fathom why "role_ids" is passed instead of…
Sudhakar
  • 2,904
  • 8
  • 33
  • 47