On Wed, Mar 16, 2011 at 10:23 PM, samjoe <[email protected]> wrote: > Hi, > > I am upgrading from CakePhp1.1 to Cakephp 1.2 When I try to load up my > page, I get the following error. > > Warning (512): SQL Error: 1066: Not unique table/alias: > 'ShoppingCart' [CORE/cake/libs/model/datasources/dbo_source.php, line > 514] > > Now below is the line that generates the error in the > shopping_carts_controller.php controller file. > > ** > > $this->ShoppingCart->unbindModel(array('belongsTo'=>array('User')));** > > Below are the definitions of the models that get used through > association > > user.php: > > <?php > > class User extends AppModel > > { > > var $name = 'User';for php4 firstname'=>'/[a-z0-9 _-]{3,}$/i', > > var $hasMany = 'Purchase'; > > var $belongsTo = array('Country', 'State', 'PaymentMethod' , > 'ShippingMethod'); > > } > > ?> > =================== > shopping_cart.php > > <?php > > class ShoppingCart extends AppModel > > { > > var $name = 'ShoppingCart'; > > var $belongsTo = array('User'); > > var $hasMany = array('ShoppingCartProduct' => > > array('className' => 'ShoppingCartProduct', > > 'dependent' => true)); > > } > > ?> > ===================== > shopping_cart_product.php > > <?php > > class ShoppingCartProduct extends AppModel > > { > > var $name = 'ShoppingCartProduct'; > > var $belongsTo = array('ShoppingCart', 'Product', 'Subproduct'); > > } > > ?> > > Now when I check the sql generated, I see something unusual which has > driven me crazy. > > The SQL it generates is below. I have removed unnecessary fields in > SQL to make the post smaller. > > > > SELECT ShoppingCart.id, > > ......., > > ShoppingCart.offer_id, ShoppingCart.subscription_id, > > ShoppingCart.persistent, ShoppingCart.decoration_id, > > ShoppingCart.coupon_code, ShoppingCart.coupon_price, > > Product.id, Product.active, Product.name, > > Product.description, Product.price, Product.quantity, > > Product.weight, Product.lead_time, Product.featured, > > ...... > > Product.user_design_id, Product.size_chart, > > Product.min_quantity, Product.allow_customization, > > Product.gender, Subproduct.id, Subproduct.product_id, > > Subproduct.name, Subproduct.price, Subproduct.weight, > > Subproduct.quantity, Subproduct.sort, Subproduct.created, > > Subproduct.modified, Subproduct.reorder_level, > > Subproduct.reorder_quantity, Subproduct.po_comments, > > Subproduct.reorder_date, Subproduct.product_code FROM > > shopping_cart_products AS **ShoppingCart** LEFT JOIN > > shopping_cart_products AS **ShoppingCart** ON > > (ShoppingCart.shopping_cart_id = ShoppingCart.id) LEFT JOIN > > products AS Product ON (ShoppingCart.product_id = > > Product.id) LEFT JOIN subproducts AS Subproduct ON > > (ShoppingCart.subproduct_id = Subproduct.id) WHERE > > ShoppingCart.session = 68900733 LIMIT 1 > > > > Question: Why is the ALIAS of the table shopping_cart_products coming > up as ShoppingCart???
It looks like you missed some of the User definition. Does User hasOne ShoppingCart? What's the purpose of ShoppingCartProduct? Is that a join model? If that's the case, it should be ProductsShoppingCarts. Are you sure you need to modelize it? And why are you unbinding User from ShoppingCart? Also, I think Country & State should be in User's $hasOne array. Ditto PaymentMethod & ShippingMethod, unless you want to allow Users to have more than one each, in which case they should be in $hasMany. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php
