cakephp-model

How to limit the fields of the associated models using find method

一曲冷凌霜 提交于 2019-12-25 01:32:31
问题 I have user model and articles model. An User hasMany articles. So when I query for a user, all fields for article table is retrieved. I want to limit it just title of articles. $user = $this->User->find('all', array('conditions' => array('User.id' => $id), 'fields' => array('User.firstName', 'Article.title'))); The fields works fine for user model. But it does not work for associated models. throws error SQL Error: 1054: Unknown column 'Article.title' in 'field list' I appreciate any help.

cakePHP HABTM don't save

帅比萌擦擦* 提交于 2019-12-24 22:50:28
问题 I have looked into all threads I could find about this Topic, but nothing solves my Problem. I have a 'customers' table and an 'employees' table which should be connected via the 'customers_employees' table. In my Form I can select the employees, but when I want to save the data he only save the 'created' and 'modified' entry and not the keys. The employee has an string id which is CHAR(36). This is my entry in the 'employee' model: public $hasAndBelongsToMany = array( 'Customer' => array(

CakePhp - Associated Data not Saving (but main model data does save)

我的未来我决定 提交于 2019-12-24 08:58:05
问题 So, I have a form in CakePhp using it's Formhelper. There are two associated models in this form: Booking & Guest. The database tables seem to be setup correctly since the page populates the values accurately enough through the associations in the model. When saving my form data, the Booking information saves but not the Guest information. I've simplified the code in the snippets below. Any ideas what I'm doing wrong? Model class Booking extends AppModel { public $name = "Booking"; /

cakePHP- retrieving from database. Models Associations & database

早过忘川 提交于 2019-12-24 04:27:15
问题 I feel pretty darn dumb for asking this question but I'm baffled, probably because I'm slightly intimidated with cakePHP(new to it, and not very comfortable),but its merits are practically forcing me to use it. So please if you could help, I appreciate it : My problem is with understanding how Model association works. After going through all the section about associations here I am still struggling and actually am not quite sure whether either my database design is flawed, or the associations

Models with two hasOne relations to same table

半世苍凉 提交于 2019-12-24 03:34:21
问题 I'm building an MMA (mixed martial arts) website with CakePHP. I've got a fights table in my database that has three columns at its simplest: id , fighter_a , and fighter_b . I'm having trouble getting my head around what type of relation my Fight model would have with my Fighter module. Am I right in thinking fighter_a and fighter_b would be two hasOne relations? I tried this with the following in my Fight model: <?php class Fight extends AppModel { public $name = 'Fight'; public $hasOne =

CakePHP: Limit Fields associated with a model

百般思念 提交于 2019-12-23 17:39:04
问题 I have several fields in some of my database tables that my CakePHP models never need to retrieve. Is there some way to set a default set of fields to fetch at the model level? For instance I retrieve some data from a third party designed database that has 50 fields per table, I use 5. I know I can set limits on fields at the time of the find() query and at the time of any associations between models, but I was wondering if there was a model-level approach. 回答1: CakePHP does not offer what

cakephp - get table names and its column details

杀马特。学长 韩版系。学妹 提交于 2019-12-23 17:15:25
问题 Does anyone knows how to get table name from model name? Also I want to get all column names and its types of that model/table name. Is it possible to get such details of given model name? Thanks. 回答1: Table Name To get the table, see $this->Model->table Or check the model for the class variable $useTable . If that's undefined, then you can infer it from the name of the model: $tableName = Inflector::tableize($this->Model->alias); See the Inflector documentation for similarly useful methods.

Getting names to show in dropdown list with cakephp

我的未来我决定 提交于 2019-12-22 14:42:10
问题 I want to show the names of all our project leaders in a dropdown list. The project leaders are only some of the employees that work in the company. Here are my tables: project_leaders ,----,----------------, | id | hr_employee_id | |----|----------------| | 1 | 18 | '----'----------------' projects ,----,------,-------------------, | id | name | project_leader_id | |----|------|-------------------| | 1 | cake | 1 | '----'------'-------------------' hr_employees ,----,------,---------, | id |

Binding multiple models Cakephp

陌路散爱 提交于 2019-12-19 11:28:07
问题 I am trying to bind 3 models in cakephp.The relation is as follows Member hasMany Member_Organaization Member_Organisations belongs to Organaization i try to use $this->Member->find('all',conditions) it just show me only data upto hasMany association. I understand that the Member model is not related directly to the organization one. but how can we do it? My code is as follows: $this->Member->bindModel( array( 'hasMany'=>array( 'NpoMember' =>array( 'className' => 'NpoMember', 'foreignKey' =>

How to associate model in CakePHP by fields not named by convention?

流过昼夜 提交于 2019-12-19 03:39:06
问题 I have two tables with field username in both. How i can specify field name for both local and foreign table? I want CakePHP will do something like ON (`T1`.`username` = `T2`.`username`)` in result. Without any changes tables will be joined with following condition: ON (`T1`.`id` = `T2`.`t1_id`)` Setting 'foreign_key' = 'username' property is not enough because it will produce query like this: ON (`t1`.`id` = `t2`.`username`)` I have two solutions. First one is use 'join' property and join