habtm

MySQL Join with 3 tables and empty rows

I'm giving up for now with my JOIN creating a view for search reasons - I need help :/ Here are my tables: Profiles id company user_id 1 ACME 2 2 Joe 4 3 Wolf 5 Users id role_id online 2 4 2010-10-08 4 2 2010-10-08 5 4 2010-10-08 Rubrics id title 1 Stee...

Could I same column to represent a foreign key to multiple tables?

I am trying to use the same column to represent a has foreign key to different columns. This is because there could be an arbitrary number of tables to be indexed using this column. Right now, my idea is to use a small varchar() field to represent which field they are indexing and then check for them my probably sub-querying for all that...

Why is CakePHP duplicating my queries? (this is not the same "too many queries" problem that is usually asked)

I've defined these relationships in my models: Lead hasMany Job Job HABTM Employee Job HABTM Truck I'm trying to do a find('all') from my Truck model, and limit the results to: All Trucks, all jobs associated with those trucks that have a certain pickup date, the employees assigned to those jobs, and the lead associated with the jo...

Habtm find with a condition

I have two tables which are related as HABTM Groups (id, name) Streams(id, Stream) connecting table groups_streams(id, group_id, stream_id) there is another model called Users which HasOne Group. From User controller i am trying to get the streams related to the Users GRoup. i am doing this but getting a Mysql Error $streams = $thi...

Deleting Habtm Relation Record

I have two models Posts and Tags Posts HasManyBelongsToMany Tags lets say a post 1 has tags world, news, paper now in the joining table i wanna remove the relation between tag paper with the post 1. but the tag paper should be there in the tags table. just in the joining table the relation should be deleted. how to do this in CakePHP...

HABTM with additional columns for recipe ingredients

For my recipe-sharing website, I want to create a database and CakePHP models for the recipes and their ingredients. I created two tables: recipes and ingredients. The third table is a HABTM table for ingredients_recipes, which also stores the amount of ingredients needed for the recipes. How do I create a model for the third table? Th...

Rails HABTM association through two join tables

I have the following models: class Friendship < ActiveRecord::Base belongs_to :user belongs_to :friend, :class_name => "User", :foreign_key => :friend_id has_and_belongs_to_many :friend_groups end class FriendGroup < ActiveRecord::Base has_and_belongs_to_many :friendships end How can I declare that FriendGroup has_and_belongs...

problem paginating habtm relations

hi, got this situation. Reports habtm users. So im trying to paginate just the Reports that are linked to the Auth user... I read when you have a habtm relationship you have to bind the model temporarily using 'hasOne' like this: funtion index(){ $conditions=array('ReportsUser.user_id'=>$this->Auth->User('id'), 'ReportsUser.report_id'=...

Ruby on Rails HABTM Multiple Dropdowns with AJAX

I have a typical HABTM relationship between members (actual members of our organization, not all have online accounts) and users (online accounts). I have an edit users page for site administrators where multiple members can be assigned to users. There are too many members to reasonably use checkboxes or a multi-select dropdown. I have ...