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
2 answers

Find in HABTM models cakephp

I has a HABTM models Request HABTM Certificates When I do $this->Request->find('all) I get this array: (int) 0 => array( 'Request' => array( 'id' => '114', 'motivo' => 'Licitação', 'status' => false, 'solicitante'…
Igor Martins
  • 2,015
  • 7
  • 36
  • 57
0
votes
2 answers

Issue with saving HABTM data in CakePHP

I’m having an issue saving HABTM data in a controller. I have an Article model, which is associated to an Event model, as articles may be about specific events in my application. I’ve read the CakePHP cookbook entry on saving HABTM data so…
Martin Bean
  • 38,379
  • 25
  • 128
  • 201
0
votes
1 answer

HABTM relationships with polymorphism

I've got a Person who can be linked to many Structures (structure is polymorphic) I've got a Venue, who can have many People, as a structure. I've got a Journal, who can have many People, as a structure. Here is my modelization : class Venue <…
0
votes
1 answer

Attach model has_and_belongs_to_many relationship in rails

I have two models Post and PostCategory both of which have has_and_belongs_to_many relationships. I have created manually three post_categories: news, don't miss and announcements. When i create a new post i want to be able to choose in which…
0
votes
3 answers

CakePHP Save data in HABTM Table

I am trying to save an array like this $myData = array( 'User' => array('id' => 17), 'Group' => array( array('group_id' => 2), array('group_id' => 3), array('group_id' => 4), array('group_id' => 5), …
lenny.myr
  • 903
  • 2
  • 11
  • 20
0
votes
1 answer

CakePHP HABTM deletion

I have Post HABTM Tags (tables: posts, tags, posts_tags). When I delete Post also deleting relations from post_tags table - it's okey, but in table tags there are still not used tags. How resolved remove not uset tags?
kicaj
  • 2,881
  • 5
  • 42
  • 68
0
votes
5 answers

Relational database design advice for laravel 4 based e-commerce application

I develop an e-commerce application with Laravel 4 and need an advice to solve my database design problem. The Problem: My client has products which have multiple variations/options. For example: Product1 = Apple Iphone 5 Color Option :…
dr.linux
  • 752
  • 5
  • 15
  • 37
0
votes
2 answers

link table in cakephp and habtm

Before any advice to read google and etc, i must write that i read a lot of articles and blogs, and for now i cant figure out how to use HABTM in my case... ;] I have order system with 3 tables and 3 models: ORDERS (order_id, customer_id,…
0
votes
2 answers

Given a 'Location' model, which has_many 'tags' (Tag), find all locations which own associated (tag) records with a certain tag column value

So I'm trying to find all Locations which have Tags with the name "school". Location has_many Tags and Tag has_many Locations via a join table accessed via the :through model method class Location < ActiveRecord::Base has_many :location_tags …
boulder_ruby
  • 38,457
  • 9
  • 79
  • 100
0
votes
2 answers

CakePHP display HABTM associations

I'm new to CakePHP and just want to display a list of associated tags in a post's view. I have searched all over the web and nothing seems to work. This is what I have at the moment: // PostController public function view($id = null) { …
0
votes
1 answer

Cakephp habtm relation unable to correctly filter by tag

I have a habtm relation between users and tags. However, it works such that our list of tags is maintained separately from the users. Such that say there are currently exactly 12 tags and N users. As new users are added, tagged with different tags…
usumoio
  • 3,500
  • 6
  • 31
  • 57
0
votes
1 answer

Rails: joining the 'has_one' and 'belongs_to' association

I have two models: class User < ActiveRecord::Base has_one :user_profile end class UserProfile < ActiveRecord::Base belongs_to :user end a User has one UserProfile, and a UserProfile belongs to a User The tables structure: User id :…
Abednego
  • 367
  • 1
  • 7
0
votes
1 answer

Save a HABTM record to database CakePHP

I am working on a followers / following system with CakePHP 2. I have setup my database with a users table, and a user_users table. The users table is the main table containing every user on the system, whilst the user_users table contains the…
0
votes
2 answers

Rails: working with double plurals (has_and_belongs_to_many)

What's the best way to work with double plurals in Rails? I've got a few has_and_belongs_to_many relationships, and I want something like: @templates = current_user.brands.templates But the closest I can do is something like…
t56k
  • 6,769
  • 9
  • 52
  • 115
0
votes
2 answers

CakePHP Retrieving data from habtm

I haven't been able to find a solution that solves this. I am trying to query my database for a list of groups to which a user belongs. Users can be in multiple groups, and groups can have multiple users. I have "users", "groups", and "groups_users"…