model-associations

CakePHP Associations error? Won't save associated table

瘦欲@ 提交于 2019-12-13 04:56:04
问题 I created a user profile where users can add their information. So on URL section I want them to put their other links like Facebook, www.facebook.com/user etc. But when I click Save nothing updates? Here is the Model for User: Models/User.php <?php class User extends AppModel { public $name = 'User'; public $hasMany = array ( 'UserWeb'=>array( 'className'=>'UserWeb', 'foreignKey'=>'user_id' ) ); } ?> The model for UserWeb: Models/UserWeb.php <?php class UserWeb extends AppModel { public

scope through associations : joins and merge

自古美人都是妖i 提交于 2019-12-13 01:00:49
问题 I have three models : User , Product and Transaction . ( Transaction belongs_to both, and User has many Product and Product has many User , through Transaction ) In my Transaction model, I have a scope for current transactions : scope :current, -> { where 'transactions.start_date IS NOT NULL AND transactions.end_date IS NULL' } I want to be able to do that in the console, in order to retrieve all the products that have a current transaction : User.first.products.owned In the console, I can

belongs_to belongs_to association only no has_many or has_one

无人久伴 提交于 2019-12-12 10:05:42
问题 Can you have a belongs_to belongs_to relationship in Rails? Search results gave me two results. The fact that I can't find very much info on the subject, seems to indicate that it shouldn't be done or is bad practice. I asked yesterday about a has_many relationship, but thought because I couldn't find information on this, I would generate a question so it is easier for people to search for this in the future. I'm paraphrasing another users answer (I hope this is ok). A Shoe can have many

Rails: Create a new entry in a model that belongs_to two other models

≯℡__Kan透↙ 提交于 2019-12-12 05:08:39
问题 Consider a Store that has_many Products which have_many Opinions. Here are Models: Store: class Store < ActiveRecord::Base attr_accessible :desc, :location, :name, :phone, :status, :url has_many :products has_many :opinions, :through => :products end Product: class Product < ActiveRecord::Base attr_accessible :desc, :name, :status, :url belongs_to :store has_many :opinions end finally, Opinion: class Opinion < ActiveRecord::Base attr_accessible :content, :eval, :status belongs_to :store

Ruby on Rails - Using callback to multiply two objects in separate tables when new entry is created

删除回忆录丶 提交于 2019-12-12 04:15:29
问题 I have 3 tables, Goals, Activities and Goal_Activities. Goal has a set value for xp and Activity takes an input from the user. Using the on_create method in Activity, I'd like to multiply the user input with the goal xp and store that in the Goal Activities table so I can keep a record of each update and eventually add them all together to create a total goal xp in the Goal table. I've found a couple of questions on SO, here and here, that cover similar topics but I'm finding it hard to get

Ruby on Rails four-way association tree

拥有回忆 提交于 2019-12-12 02:09:30
问题 The big picture: I am creating an app to track temporal events historically. I am setting it up with four main models: Users, Events, Stories and Images. The idea is that any given user can create an Event, and add Stories and/or Images to his own Event or to any other one. But both Stories and Images are always attached to a certain Event, and any other model belongs to the User who created it (for filtering and editing purposes) The general structure of the associations would be something

CakePHP Elements not updating table

旧城冷巷雨未停 提交于 2019-12-12 00:10:53
问题 Hi Im trying to make a posts sections for a university project on video streaming website. I have a posts controller and model. I thought that I would create an element for the posts input box so that I could echo this out in the localhost/evolvids/uploads/watch/ section, however when I submit a post I get thrown a MISSING CONTROLLER error. This is my code for the Posts Element <div class="postsform"> <table> <tr> <td> <?php echo $this->Form->create('Posts', array('action'=>'add')); echo

Mysql : Association table

五迷三道 提交于 2019-12-11 14:13:26
问题 Using mySQL, I have these tables: Person ---------- id (PK) name ... Person_Association ---------- id_Person1 (FK Person.id) id_Person2 (FK Person.id) I want each Person_Association to be unique: if (#1, #2) exists, then neither (#1, #2) nor (#2, #1) can be inserted. To do that I've added a field and a trigger to Person_Association, like this: Person_Association ---------- id_Person1 (FK Person.id) id_Person2 (FK Person.id) unique_id (PK) CREATE TRIGGER `Person_Association_BINS` BEFORE INSERT

Rails: How to make has_many :through association work with Single Table Inheritance

假如想象 提交于 2019-12-11 08:14:51
问题 So in my current project I have an Article model that can have different kinds of Transactions. It has one main Transaction, but under certain circumstances it can have multiple sub-transactions. Until now I set it up like this: class Article < ActiveRecord::Base has_one :transaction, inverse_of: :article has_many :partial_transactions, through: :transaction, source_type: 'MultipleFixedPriceTransaction', source: 'PartialFixedPriceTransaction', inverse_of: :articles end class Transaction <

Rails ActiveRecord Association

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 02:17:32
问题 Okay, so here is my question. I have a 3 different models, People, Roles, Client, and Store. Clients have many Stores and can also have many people. Stores have many people. People have various roles. 1 Person can work at multiple stores, and they may have different roles at each store. For example. Joe may be an assistant manager at one store and a manager at another store. What I would like to be able to do is pull the correct roles by doing something like Store.find(1).people.find(1).roles