Hey all,
I have a n...n structure for two tables, makes and models. So far no problem.
In a third table (products) like:
id
make_id
model_id
...
My problem is creating a view for products of one specifi make inside my ProductsController containing just that's make models:
I thought this could work:
var $uses = array('Make', 'Model...
Heyall,
I am using a very intrinsic database with a CakePHP application and so far my multi-models views and controllers are working fine. I have a singular table (Entity) that have it's id on several other tables as the Foreign Key entity_id
Some tables are one to one relations (Like a Company is one Entity) and some are one to many (...
I have a situation where I have two models, companies and permissions, where companies is in a separate database from my permissions database. This is a has and belongs to many relationship because each company can have many permissions and each permission can belong to many companies.
The reason the two databases are split is because ...
In my Rails app I have three models, Projects, BlogPosts and Images. Projects and BlogPosts can have many linked images and an image can be linked to a Project, a BlogPost or both.
What is the best way of setting up the associations to make this work in Rails?
...
Hello,
I'm working on a CakePHP 1.2 application. I have a model "User" defined with a few HABTM relationships with other tables through a join table.
I'm now tasked with finding User information based on the data stored in one of these HABTM tables. Unfortunately, when the query executes, my condition is rejected with an error about a ...
How do I update additional data in HABTM tables.
For Example: I have movies, people and HABTM movies_people tables, but there is additional persontype_id field in movies_people table which indicates role of this person in that particular movie. How do I add/change this value?
...
In Rails you can use nested routes to create RESTful routes for has_one and has_many relationships. Examples can be found on the Rails Guides
I'd like to ask if there is a good way to configure RESTful routes for habtm relationships? For example if I have a relationship A-habtm-B, my idea is to configure nested routes for A has_many B, ...
I am trying to update tables with a has and belongs to many (HABTM) relationship.
When my join table looked like this:
CREATE TABLE IF NOT EXISTS `items_labels` (
`item_id` int(11) NOT NULL,
`label_id` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
I use CakePHP, so I could update the tables with $this->Item->save($data) ...
Is there anything explicitly wrong with using has_and_belongs_to_many associations in rails instead of has_many :through? I'm aware of these articles describing differences and work arounds, but they are from 2006. From things I've read on SO, it seems like people think that habtm is old and clunky, but what if a simple many to many jo...
I have a Service Types table containing id and name of a couple of dozen services.
I have a Projects table that has to have a list of Proposed Services, and a list of Accepted Services.
I know that I would use HABTM on both sides with a project_service_types table in between.
I can't quite figure out what to do when I have 2 different...
I read a lot about tagging in CakePHP but I can't find a "clean" way to save a Post and the Tags to this post. I have all which is necessary the Post Table, Model and Controller, the Tag table, Model and Controller and the posts_tags table. I created the HABTM Associations in the Post and the Tag Model.
If I want to save a new post, I w...
I'm using a simple model for user authorisation with two ActiveRecords User and Role
User and Role have a HABTM relation to each other.
I tried to created a user interface for assigning roles to users with simple checkboxes - just like in Railscasts Episode #17.
My problem is that neither User#new nor User#update_attributes use the par...
I'm trying to save data with following structure:
As you can see, there is HABTM association between users and experiences table. And another HABTM between *experiences_users* and tags. I created following form:
<?php echo $form->create('Experience', array('action' => 'addClassic'));?>
<?php
echo $form->input('Experience.date...
hi all
I have a product model that has many sections and a section can belong to many products.
The section model has subclasses as features, standardAccessories and OptionalAccessories in a STI. Each having field title, body, image url and (optionalAccessories) has price.
my models are
class Product < ActiveRecord::Base
has_and...
Ok, stupid question. How do you remove a HABTM associated item without deleting the item itself? For instance, say I have 3 STUDENTS that are in SCIENCE class together. How do I remove the SCIENCE object from the STUDENTS_CLASSES table without deleting the actual SCIENCE reference? I'm guessing that Student.Classes.first.delete is...
Hi guys...please help me, i'm really struggling with this...
Authors can write post, and authors can love other authors' posts...
So posts belong to author (when authors write them), but posts habtm
authors (when authors love them).
For example i'd like to get posts ordered by number of postlovers and
created in the last 24 hours. He...
I have a Rails app with Users, and each user HABTM Roles.
I want to select Users without a specific role. I have searchlogic at my disposal, and I'm lost. I've tried using a combination of conditions and joins and includes and what not, but I can't seem to nail it. This works:
User.find(:all, :conditions => ['role_id != ?', Role[:admin...
Might be a newbie question as I'm trying to see what all these "PHP frameworks" are at my free time.
For starters I want to add multiple tags to multiple photos. I have a tags model and mot model (the photos).
Snip of mot model:
var $hasAndBelongsToMany = array(
'Tag' =>
array(
'cl...
I am creating multiple associations in one go and there are a few problems when it comes to saving.
I have the following code:
<?php
foreach($userData as $user) {
$data = array('User' => array('id' => $user['id']), 'Site' => array('id' => $user['site_id']));
$this->User->save($data);
}
?>
I have experimented with formatting t...
Can anyone explain to me how the (HABTM or many to many) "has and belongs to many" principle works? Say I have a users table and books table and then I have a table users_books where the IDs are. When would I need to actually use this principle and how would it work?
...