habtm

UpdateAll and HABTM in CakePHP

I have two models and a join table, User, Post and posts_users. The posts_users table contains a few extra fields, one of which is is_active. I want to set all of a users posts to active providing the user is active themselves. I have the following $this->Post->PostsUser->updateAll(array('PostsUser.is_active' => 1), array('PostsUser.u...

CakePHP form helper - HABTM multiple checkbox styling

I have two tables restaurants n cuisines which are related to each other as HATBM table cusinies have certain fixed entries - 54 number i restarurant can hve any number of cuisines. on baking the application this came with a multiple select. since i wanted check boxes i used array( 'type' => 'select', 'multiple' => 'checkbox') to conve...

Need data from a many:many join in a Rails view

Its maybe not the best solution in most cases, but i want a table with data form 3 tables. class Media < ActiveRecord::Base belongs_to :user belongs_to :type has_many :ratings end class User < ActiveRecord::Base has_many :medias has_many :ratings end class Rating < ActiveRecord::Bas...

Best implementation of a multi-model association in rails?

Alright, a Rails Noob here, :D It looks like has__many :through is the latest greatest way to handle many to many relationships, but I am trying to keep this simple. Hopefully one of you guru's out there have handled this situation before: Here is the basic model setup I have now: class User < ActiveRecord::Base has_and_belongs_to_...

How to get all tags that do NOT have posts associated in CakePHP

Hi, I'm doing a blog in CakePHP, so I have two tables in my database that are HABTM related: posts and tags. Because they are HABTM related I also have a poststags table keeping track of relations. I'd like to have a method in my tags_controller that will delete all unused tags. How do I find all tags that are NOT associated with any ...

How can I load HABTM-with-foreign-key relationships in my fixtures ?

I have the following two models: School and User, and a HABTM relationship between them, with a join table. In this join table, the foreign key refering to the User table is not called user_id but student_id. class School < ActiveRecord::Base has_and_belongs_to_many :students, :class_name => "User", :join_table => "schools_students",...

Yii framework Many to Many relationships..

What is the method to save and update Many to Many relationship in Yii framework? ...

HABTM-Relation : Create a relation for all other records

Hi! If i want to add a record to TABLE A, is there an efficient way to add a record in the JOIN TABLE for many (or all) records in TABLE B? I try to build a simple task management (in CakePHP). An user adds a task and there will be added a connection to each other user in the same group as the current user. At the moment, I use th...

cakephp habtm relationship (saving data)

Question related to HABTM has been posted in some good numbers on stackoverflow but I am still looking for a solution to my problem. I am creating an application that allows for creation of topics based on a particular subcategory. While adding a topic the user is asked for tags (on the same form). Now when the user has finished adding ...

Validating length of habtm association without saving.

I have a user model with a HABTM relationship to groups. I do not want a user to be able to be in more than 5 groups, so would like to validate the length of the HABTM relationship. On the edit user page I have a list of checkboxes where the user can select the groups they want to be in (I'm using formtastic for the form). In my users...

Doing something before saving a form used with HABTM

Hi I currently have 3 tables. snippet tags snippet_tags I'm using HABTM. So I did a form to save a snippet with tags. Keywords are in a text field, separated by commas. What I need to do is to take the string from this text field, loop on the keywords, check if they exist, if not create them, and THEN save the snippet. I tried with...

HABTM data not saving (cakephp).

Hello, I have two models related HABTM (documents and people). class Person extends AppModel { var $name = 'Person'; var $hasAndBelongsToMany = array( 'Document' => array( 'className' => 'Document', 'joinTable' => 'documents_people', 'foreignKey' => 'person_id', 'associati...

DataMapper has n through Resource DELETE (Remove from association) not working

Hi, I'm have this two classes class User include DataMapper::Resource property :id, Serial property :name, String has n :posts, :through => Resource end class Post include DataMapper::Resource property :id, Serial property :title, String property :body, Text has n :users, :through => Resource end So onc...

HABTM Double-Nested fields_for

Interesting segment of code that I can't get to work. I have the following models/relationships (unnecessary code excluded) class Service < ActiveRecord::Base belongs_to :service_category, :foreign_key => "cats_uid_fk" belongs_to :service_type, :foreign_key => "types_uid_fk" has_and_belongs_to_many :service_subtypes, :join_table =...

HABTM Query help

I have a HABTM relationship between 'articles' and 'tags' Problem: I'm only looking for articles with BOTH the tag 'sports' and 'outdoors' but not articles with only one of these tags. I tried this: SELECT DISTINCT article.id, article.name FROM articles inner JOIN tags ON (tags.name IN ('outdoors', 'sports') inner JOIN articles_tags O...

Edit of self referencing HABTM in cakephp works, sometimes

I'm using a self referencing HABTM model with Participants. You sign up for an event and when you log in to your reservation/profile you see a list of other participants and you can choose to add yourself and others into various groups; share hotel room, share transportation from airport etc. What I've managed so far: 1) In my profile...

ASP.Net MVC HABTM Association

I must be missing something, when trying to define a HABTM association with 2 of my models. I have a "Product" table, and a "Category" table, and a "ProductsCategories" join table. In SQL Server, I am defining the Relationship between the tables on the join table. However, when I create the LINQ to SQL model "Product," I get "Product....

MySQL - counting with HABTM relationships

I have 3 tables: 'cards', 'tags' and 'cardstags', where cards HABTM tags Question: What query do I execute on the 'tags' table to count the number of associated 'cards' rows? I'm looking for something like this: tags.name | count ----------+------ cricket | 15 (15 cards are tagged as 'cricket') soccer | 23 football | ...

rails habtm relation

Hi I have 2 models which have a has_and_belongs_to_many relation: class Category < ActiveRecord::Base has_and_belongs_to_many :templates end class Template < ActiveRecord::Base has_and_belongs_to_many :categories end I want to know how can I get a category name through this relation, for example I find a first template: t = Tem...

Cakephp retrieving HABTM which Conditions

I'm using cakephp and would like to display all Submissions which are part of Category 'X' I have 4 tables with a HABTM relationship. Users -> (haveMany) -> Submissions <-> (hasAndBelongsToMany) <-> Categories but I would like to do so using the $this->paginate() and for each submission I would like to display the user who posted the s...