Skip to content

Instantly share code, notes, and snippets.

@beporter
Created November 2, 2015 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beporter/d8405c5d1a5844985a02 to your computer and use it in GitHub Desktop.
Save beporter/d8405c5d1a5844985a02 to your computer and use it in GitHub Desktop.
A quick diff and script to resolve cakephp/cakephp#7626 until that PR can be merged. Save these files in your project root dir, make the .sh executable, and run it. Assumes CakePHP v3.1.3 is in use.
#!/usr/bin/env bash
#---------------------------------------------------------------------
usage ()
{
cat <<EOT
${0##*/}
Apply the belongstomany.patch file to your cakephp source in vendor/
Usage:
bin/${0##*/} <table>
EOT
exit 0
}
if [ "$1" = '-h' ]; then
usage
fi
DIR="$( cd -P "$( dirname "$0" )"/.. >/dev/null 2>&1 && pwd )"
printf "\n## Applying patch.\n"
patch vendor/cakephp/cakephp/src/ORM/Association/BelongsToMany.php belongstomany.patch
printf "\n## To undo, run 'composer install' or reset your vendor/ dir"
printf "\n## or run this again and choose 'Y' when prompted to reverse.\n"
--- vendor/cakephp/cakephp/src/ORM/Association/BelongsToMany.php 2015-10-30 10:01:28.000000000 -0500
+++ vendor/cakephp/cakephp/src/ORM/Association/BelongsToMany.php 2015-10-30 10:01:49.000000000 -0500
@@ -758,6 +758,7 @@
$associationConditions = $this->conditions();
if ($associationConditions) {
+ $existing->contain($this->target()->alias());
$existing->andWhere($associationConditions);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment