logo
down
shadow

CakePHP 2.x HABTM find data which have relationship by condition


CakePHP 2.x HABTM find data which have relationship by condition

By : Joshua
Date : November 22 2020, 10:31 AM
like below fixes the issue Well, here is a "ugly" solution that works, if someone is interested in:
code :
        $userId = $this->Auth->user('id');
        $joins = array(
            array('table'=>'sdirectories_users',
                'alias' => 'SdirectoriesUser',
                'type'=>'inner',
                'conditions'=> array(
                    'Sdirectory.id = SdirectoriesUser.sdirectory_id'
                )),
            array('table'=>'users',
                'alias' => 'User',
                'type'=>'inner',
                'conditions'=> array(
                    'User.id = SdirectoriesUser.user_id',
                    'User.id' => $userId
                ))
        );
        $options = array(
            'joins' => $joins,
            'contain' => array(
                'User' => array('fields' => 'id')
            ),
            'fields' => array('DISTINCT Sdirectory.id', 'Sdirectory.*')
        );
        $allSdirectories = $this->Sdirectory->find('all',
            $options
        );


Share : facebook icon twitter icon
cakephp habtm relationship (saving data)

cakephp habtm relationship (saving data)


By : Ahmad Khan
Date : March 29 2020, 07:55 AM
Any of those help With the help of Mr. Stornvig, I was able to solve my problem. Here is the link that describes the complete procedure of how to achieve such functionality in cakephp. This is an awesome tutorial for learning more about HABTM relationship.
For version 1.3 I found out this technique to be useful. Here are the steps:
code :
echo $form->create('Job');
echo $form->input('title');
echo $form->input('description');
echo $form->input('location');
echo $form->input('Category');//note the caps and single plural
$form->end('Submit');
CakePHP returning the wrong column in a find query in a HABTM relationship

CakePHP returning the wrong column in a find query in a HABTM relationship


By : user3630582
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Your comment explains it all :D You said that you have something like this:
code :
var $hasAndBelongsToMany = array(
   'Follower' => array( 
       'className' => 'Follower',
       'joinTable' => 'user_users',
       'foreignKey' => 'user_id', 
       'associationForeignKey' => 'follower_user_id'
));
CakePHP - HABTM relationship and find()

CakePHP - HABTM relationship and find()


By : artnerfy
Date : March 29 2020, 07:55 AM
wish help you to fix your issue You are performing a find on Video model, when you showed association on Category and Post models, not Video. Assuming this is a typo error:
If you want to search, as you stated, posts that are of "News" category do in posts_controller.php:
code :
$this->Post->Category->find('all', array('conditions'=>array('Category.name'=>'News')) );
$this->Category->find('all', array('conditions'=>array('Category.name'=>'News')) );
Using a contain in a find with HABTM relationship in cakephp

Using a contain in a find with HABTM relationship in cakephp


By : Anil Khairnar D
Date : March 29 2020, 07:55 AM
will be helpful for those in need if you are calling find on Country model it is the one you should contain, like this: $this->Entity->Country->contain().
Also, you can't put fields directly on the contain call. Try calling like this: $this->Entity->Country->contain(array('fields' => 'ticker')).
CakePHP find items without HABTM relationship record

CakePHP find items without HABTM relationship record


By : mihai
Date : March 29 2020, 07:55 AM
may help you . As the CookBook :: Subqueries you could do
code :
$db = $this->User->getDataSource();
$subQuery = $db->buildStatement(
    array(
        'fields'     => array('"DocumentsTag"."tag_id"'),
        'table'      => $db->fullTableName($this->DocumentsTag),
        'alias'      => 'DocumentsTag',
        'limit'      => null,
        'offset'     => null,
        'joins'      => array(),
        'conditions' => null,
        'order'      => null,
        'group'      => null
    ),
    $this->DocumentsTag
);
$subQuery = ' "Tag"."id" NOT IN (' . $subQuery . ') ';
$subQueryExpression = $db->expression($subQuery);

$conditions[] = $subQueryExpression;

$this->User->find('all', compact('conditions'));
Related Posts Related Posts :
  • How can I use dataproc to pull data from bigquery that is not in the same project as my dataproc cluster?
  • DMSDK Transactions - Marklogic JAVA API
  • Unison move root with rootalias
  • Why is Crystal .should be producing a spurious error
  • zendframework 3 - identity view helper error
  • SPARQL delete query dotNetRDF does not modify RDF file
  • 403 Forbidden Error. Hosting a website on my PC with WAMP?
  • TimerOne and Serial Libraries
  • o I need to set somehow create_engine put in singleton to be like singleton?
  • how to count instances between a range in libre office calc 4
  • Assign integer values to color in opengl es 2.0
  • circle with conical gradient in android
  • items not showing in mvxlistview
  • java.lang.ClassNotFoundException: org.sonatype.aether.version.InvalidVersionSpecificationException
  • Time complexity (in big-O notation) of the following code?
  • Error: Bad value twitter:domain for attribute name on element meta: Keyword twitter:domain is not registered
  • AHK: Unpress All Pressed Keys
  • Decimal output parameter rounded to integer in EF5.0
  • Error when deploying ear in weblogic 11g
  • autocomplete with extjs :ComboBox with REMOTE query store
  • How to make full background color in skeleton, responsive 960 grid?
  • How to send a variable of type struct in MPI_Send()?
  • I accidentally deleted a picture in my album on FB and it was uploaded years ago and I dont have a copy how can i get it
  • Does setting techOrder for video.js really work?
  • What are XMPP extensions (XEPs), and how do I use them?
  • Interactive alternative to dot?
  • Doctrine 2: how do you use a subquery column (in the SELECT clause)
  • Merging graphs using boost graph
  • Creating Order Item Grid in Magento
  • Can't remap Ctrl+W to the F2 key in autohotkey
  • Property 'throw' does not exist on type 'typeof Observable'
  • Unable to deploy SAPUI5 application with 404 error
  • Xcode 10 build fail rm permission denied in /bin/sh/
  • Handling quorum writies fail on Cassandra
  • How to finalize log file just after time is over when using logback SizeAndTimeBasedFNATP?
  • Write custom widget with GTK3
  • How to remove UINavigationBar inner shadow in iOS 7?
  • Wordpress dynamic widget by location?
  • XDocument replace all node value with lower case
  • Invalid tagdir attribute while web-fragment is used
  • Set default font/text size in RTF Control
  • what video formats supported by chromecast device (mp4,flv,m3u8,flv,avi)?
  • sbcl - how to muffle "undefined variable" warning?
  • Get an eventbrite event ID
  • Obtain date without timestamp in DB2
  • Cron job to SFTP files in a directory
  • Draw two head arrows in fabric.js
  • YOLO darknet vs darkflow
  • Parse custom rss tags using Rome API
  • Creating text editor like EDIT on Command Prompt using FreePascal
  • Subplot hides xlabel
  • NServiceBus long running process that timesout
  • Qt4 - How to add a row in a QTableWidget when sorting is enable?
  • Cancel command in Grunt that hasn't been launched
  • Canvas globalCompositeOperation is not working correctly
  • HTML.Kendo().Dropdownlist set default item
  • vagrant up failed, /dev/vboxnetctl: no such file or directory
  • How to use jssor carousel to build client carousal
  • Theory what is meant by validating security concerns for these user groups
  • How to build correct SPARQL Query
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org