Elasticsearch NEST, case sensitive multi-field - case

I struggle to make this multi-field setting to case sensitive, what's the missing piece?
Thanks in advance!!.
targetClientProperties.MapFluent< CMSDocument >
( m => m. MapFromAttributes()
.Properties( p => p.MultiField( mf => mf
.Name ( n => n.Hash )
.Fields(fs => fs
.String(s => s.Name(t => t.PropertyHash))
.String(s => s.Name(t => t.TileHash))
))));

Set the fields to not_analyzed:
targetClientProperties.MapFluent< CMSDocument >
( m => m. MapFromAttributes()
.Properties( p => p.MultiField( mf => mf
.Name ( n => n.Hash )
.Fields(fs => fs
.String(s => s.Name(t => t.PropertyHash).Index(FieldIndexOption.not_analyzed))
.String(s => s.Name(t => t.TileHash).Index(FieldIndexOption.not_analyzed))
))));

Related

How can I add a filter for specific categories on functions.php?

I am on functions.php and I want to add this filter:
function graphene_alter_the_query( $request ) {
$dummy_query = new WP_Query();
$dummy_query->parse_query( $request );
if (!is_category('25')) {
$request['gdsr_sort'] = 'rating';
}
else {
$request['gdsr_sort'] = 'comment_count';
}
return $request;
}
add_filter( 'request', 'graphene_alter_the_query' );
the filter should do the same thing for all categories except cat 25 but seems like it cant tell it apart like if the IF condition is not detecting the category so I tried to debug it by looking at the values in WP_Query and I get this:
$myquery = new WP_Query(); print_r($myquery);
WP_Query Object ( [query] => Array ( [category_name] => 'my cat' ) [query_vars] => Array ( [category_name] => 'my cat' [error] => [m] => [p] => 0 [post_parent] => [subpost] => [subpost_id] => [attachment] => [attachment_id] => 0 [name] => [pagename] => [page_id] => 0 [second] => [minute] => [hour] => [day] => 0 [monthnum] => 0 [year] => 0 [w] => 0 [tag] => [cat] => [tag_id] => [author] => [author_name] => [feed] => [tb] => [paged] => 0 [meta_key] => [meta_value] => [preview] => [s] => [sentence] => [title] => [fields] => [menu_order] => [embed] => [category__in] => Array ( ) [category__not_in] => Array ( ) [category__and] => Array ( ) [post__in] => Array ( ) [post__not_in] => Array ( ) [post_name__in] => Array ( ) [tag__in] => Array ( ) [tag__not_in] => Array ( ) [tag__and] => Array ( ) [tag_slug__in] => Array ( ) [tag_slug__and] => Array ( ) [post_parent__in] => Array ( ) [post_parent__not_in] => Array ( ) [author__in] => Array ( ) [author__not_in] => Array ( ) ) [tax_query] => WP_Tax_Query Object ( [queries] => Array ( [0] => Array ( [taxonomy] => category [terms] => Array ( [0] => 'my cat' ) [field] => slug [operator] => IN [include_children] => 1 ) ) [relation] => AND [table_aliases:protected] => Array ( ) [queried_terms] => Array ( [category] => Array ( [terms] => Array ( [0] => 'my cat' ) [field] => slug ) ) [primary_table] => [primary_id_column] => ) [meta_query] => [date_query] => [post_count] => 0 [current_post] => -1 [in_the_loop] => [comment_count] => 0 [current_comment] => -1 [found_posts] => 0 [max_num_pages] => 0 [max_num_comment_pages] => 0 [is_single] => [is_preview] => [is_page] => [is_archive] => 1 [is_date] => [is_year] => [is_month] => [is_day] => [is_time] => [is_author] => [is_category] => 1 [is_tag] => [is_tax] => [is_search] => [is_feed] => [is_comment_feed] => [is_trackback] => [is_home] => [is_privacy_policy] => [is_404] => [is_embed] => [is_paged] => [is_admin] => [is_attachment] => [is_singular] => [is_robots] => [is_favicon] => [is_posts_page] => [is_post_type_archive] => [query_vars_hash:WP_Query:private] => 6d85cdf18f3e6a58a470a3002d5807fc [query_vars_changed:WP_Query:private] => [thumbnails_cached] => [stopwords:WP_Query:private] => [compat_fields:WP_Query:private] => Array ( [0] => query_vars_hash [1] => query_vars_changed ) [compat_methods:WP_Query:private] => Array ( [0] => init_query_flags [1] =>
but both tag_id and cat appear empty. Why is that?

WooCommerce get product name, price etc from Object

I have this code:
$args = array(
'category' => array( 'membership-level' ),
'orderby' => 'name',
);
$products = wc_get_products( $args );
echo '<pre>';
print_r( $products );
echo '</pre>';
And its output is something like that:
Array
(
[0] => WC_Product_Simple Object
(
[object_type:protected] => product
[post_type:protected] => product
[cache_group:protected] => products
[data:protected] => Array
(
[name] => Test Level
[slug] => test-level
[date_created] => WC_DateTime Object
(
[utc_offset:protected] => 0
[date] => 2022-04-10 11:54:18.000000
[timezone_type] => 1
[timezone] => +00:00
)
[date_modified] => WC_DateTime Object
(
[utc_offset:protected] => 0
[date] => 2022-04-10 11:54:18.000000
[timezone_type] => 1
[timezone] => +00:00
)
[status] => publish
[featured] =>
[catalog_visibility] => visible
[description] => Hello Test Level
[short_description] =>
[sku] =>
[price] => 12
[regular_price] => 12
[sale_price] =>
[date_on_sale_from] =>
[date_on_sale_to] =>
[total_sales] => 1
[tax_status] => taxable
[tax_class] =>
[manage_stock] =>
[stock_quantity] =>
[stock_status] => instock
[backorders] => no
[low_stock_amount] =>
[sold_individually] =>
[weight] =>
[length] =>
[width] =>
[height] =>
[upsell_ids] => Array
(
)
[cross_sell_ids] => Array
(
)
[parent_id] => 0
[reviews_allowed] => 1
[purchase_note] =>
[attributes] => Array
(
)
[default_attributes] => Array
(
)
[menu_order] => 0
[post_password] =>
[virtual] => 1
[downloadable] =>
[category_ids] => Array
(
[0] => 141
)
[tag_ids] => Array
(
)
[shipping_class_id] => 0
[downloads] => Array
(
)
[image_id] =>
[gallery_image_ids] => Array
(
)
[download_limit] => -1
[download_expiry] => -1
[rating_counts] => Array
(
)
[average_rating] => 0
[review_count] => 0
)
[supports:protected] => Array
(
[0] => ajax_add_to_cart
)
[id:protected] => 5275
[changes:protected] => Array
(
)
[object_read:protected] => 1
[extra_data:protected] => Array
(
)
[default_data:protected] => Array
(
[name] =>
[slug] =>
[date_created] =>
[date_modified] =>
[status] =>
[featured] =>
[catalog_visibility] => visible
[description] =>
[short_description] =>
[sku] =>
[price] =>
[regular_price] =>
[sale_price] =>
[date_on_sale_from] =>
[date_on_sale_to] =>
[total_sales] => 0
[tax_status] => taxable
[tax_class] =>
[manage_stock] =>
[stock_quantity] =>
[stock_status] => instock
[backorders] => no
[low_stock_amount] =>
[sold_individually] =>
[weight] =>
[length] =>
[width] =>
[height] =>
[upsell_ids] => Array
(
)
[cross_sell_ids] => Array
(
)
[parent_id] => 0
[reviews_allowed] => 1
[purchase_note] =>
[attributes] => Array
(
)
[default_attributes] => Array
(
)
[menu_order] => 0
[post_password] =>
[virtual] =>
[downloadable] =>
[category_ids] => Array
(
)
[tag_ids] => Array
(
)
[shipping_class_id] => 0
[downloads] => Array
(
)
[image_id] =>
[gallery_image_ids] => Array
(
)
[download_limit] => -1
[download_expiry] => -1
[rating_counts] => Array
(
)
[average_rating] => 0
[review_count] => 0
)
[data_store:protected] => WC_Data_Store Object
(
[instance:WC_Data_Store:private] => WC_Product_Data_Store_CPT Object
(
[internal_meta_keys:protected] => Array
(
[0] => _visibility
[1] => _sku
[2] => _price
[3] => _regular_price
[4] => _sale_price
[5] => _sale_price_dates_from
[6] => _sale_price_dates_to
[7] => total_sales
[8] => _tax_status
[9] => _tax_class
[10] => _manage_stock
[11] => _stock
[12] => _stock_status
[13] => _backorders
[14] => _low_stock_amount
[15] => _sold_individually
[16] => _weight
[17] => _length
[18] => _width
[19] => _height
[20] => _upsell_ids
[21] => _crosssell_ids
[22] => _purchase_note
[23] => _default_attributes
[24] => _product_attributes
[25] => _virtual
[26] => _downloadable
[27] => _download_limit
[28] => _download_expiry
[29] => _featured
[30] => _downloadable_files
[31] => _wc_rating_count
[32] => _wc_average_rating
[33] => _wc_review_count
[34] => _variation_description
[35] => _thumbnail_id
[36] => _file_paths
[37] => _product_image_gallery
[38] => _product_version
[39] => _wp_old_slug
[40] => _edit_last
[41] => _edit_lock
)
[must_exist_meta_keys:protected] => Array
(
[0] => _tax_class
)
[extra_data_saved:protected] =>
[updated_props:protected] => Array
(
)
[meta_type:protected] => post
[object_id_field_for_meta:protected] =>
)
[stores:WC_Data_Store:private] => Array
(
[coupon] => WC_Coupon_Data_Store_CPT
[customer] => WC_Customer_Data_Store
[customer-download] => WC_Customer_Download_Data_Store
[customer-download-log] => WC_Customer_Download_Log_Data_Store
[customer-session] => WC_Customer_Data_Store_Session
[order] => WC_Order_Data_Store_CPT
[order-refund] => WC_Order_Refund_Data_Store_CPT
[order-item] => WC_Order_Item_Data_Store
[order-item-coupon] => WC_Order_Item_Coupon_Data_Store
[order-item-fee] => WC_Order_Item_Fee_Data_Store
[order-item-product] => WC_Order_Item_Product_Data_Store
[order-item-shipping] => WC_Order_Item_Shipping_Data_Store
[order-item-tax] => WC_Order_Item_Tax_Data_Store
[payment-token] => WC_Payment_Token_Data_Store
[product] => WC_Product_Data_Store_CPT
[product-grouped] => WC_Product_Grouped_Data_Store_CPT
[product-variable] => WC_Product_Variable_Data_Store_CPT
[product-variation] => WC_Product_Variation_Data_Store_CPT
[shipping-zone] => WC_Shipping_Zone_Data_Store
[webhook] => WC_Webhook_Data_Store
[order-item-line_item_removed] => WC_Order_Item_Product_Data_Store
[order-item-line_item_switched] => WC_Order_Item_Product_Data_Store
[order-item-coupon_pending_switch] => WC_Order_Item_Coupon_Data_Store
[order-item-fee_pending_switch] => WC_Order_Item_Fee_Data_Store
[subscription] => WCS_Subscription_Data_Store_CPT
[product-variable-subscription] => WCS_Product_Variable_Data_Store_CPT
[product-subscription_variation] => WC_Product_Variation_Data_Store_CPT
[order-item-line_item_pending_switch] => WC_Order_Item_Product_Data_Store
[report-revenue-stats] => Automattic\WooCommerce\Admin\API\Reports\Orders\Stats\DataStore
[report-orders] => Automattic\WooCommerce\Admin\API\Reports\Orders\DataStore
[report-orders-stats] => Automattic\WooCommerce\Admin\API\Reports\Orders\Stats\DataStore
[report-products] => Automattic\WooCommerce\Admin\API\Reports\Products\DataStore
[report-variations] => Automattic\WooCommerce\Admin\API\Reports\Variations\DataStore
[report-products-stats] => Automattic\WooCommerce\Admin\API\Reports\Products\Stats\DataStore
[report-variations-stats] => Automattic\WooCommerce\Admin\API\Reports\Variations\Stats\DataStore
[report-categories] => Automattic\WooCommerce\Admin\API\Reports\Categories\DataStore
[report-taxes] => Automattic\WooCommerce\Admin\API\Reports\Taxes\DataStore
[report-taxes-stats] => Automattic\WooCommerce\Admin\API\Reports\Taxes\Stats\DataStore
[report-coupons] => Automattic\WooCommerce\Admin\API\Reports\Coupons\DataStore
[report-coupons-stats] => Automattic\WooCommerce\Admin\API\Reports\Coupons\Stats\DataStore
[report-downloads] => Automattic\WooCommerce\Admin\API\Reports\Downloads\DataStore
[report-downloads-stats] => Automattic\WooCommerce\Admin\API\Reports\Downloads\Stats\DataStore
[admin-note] => Automattic\WooCommerce\Admin\Notes\DataStore
[report-customers] => Automattic\WooCommerce\Admin\API\Reports\Customers\DataStore
[report-customers-stats] => Automattic\WooCommerce\Admin\API\Reports\Customers\Stats\DataStore
[report-stock-stats] => Automattic\WooCommerce\Admin\API\Reports\Stock\Stats\DataStore
)
[current_class_name:WC_Data_Store:private] => WC_Product_Data_Store_CPT
[object_type:WC_Data_Store:private] => product-simple
)
[meta_data:protected] =>
)
Now I want to get the name, and price from that output. If I use $products->get_name(); then I am getting a error message:
Fatal error: Uncaught Error: Call to a member function get_name() on
array in
So, my question is how can I use the WooCommerce methods to get name, price, etc from that $product variable?

phpexcel line chart not taking cell value

i am using php excel to generate chart, but its not taking cell value. for reference you can refer http://uvresins.net/images/xls.png
My chart variable return :
PHPExcel_Chart Object
(
[_name:PHPExcel_Chart:private] => chart1
[_worksheet:PHPExcel_Chart:private] =>
[_title:PHPExcel_Chart:private] => PHPExcel_Chart_Title Object
(
[_caption:PHPExcel_Chart_Title:private] => Scgcc
[_layout:PHPExcel_Chart_Title:private] =>
)
[_legend:PHPExcel_Chart:private] => PHPExcel_Chart_Legend Object
(
[_position:PHPExcel_Chart_Legend:private] => tr
[_overlay:PHPExcel_Chart_Legend:private] =>
[_layout:PHPExcel_Chart_Legend:private] =>
)
[_xAxisLabel:PHPExcel_Chart:private] =>
[_yAxisLabel:PHPExcel_Chart:private] => PHPExcel_Chart_Title Object
(
[_caption:PHPExcel_Chart_Title:private] => Value ($k)
[_layout:PHPExcel_Chart_Title:private] =>
)
[_plotArea:PHPExcel_Chart:private] => PHPExcel_Chart_PlotArea Object
(
[_layout:PHPExcel_Chart_PlotArea:private] =>
[_plotSeries:PHPExcel_Chart_PlotArea:private] => Array
(
[0] => PHPExcel_Chart_DataSeries Object
(
[_plotType:PHPExcel_Chart_DataSeries:private] => lineChart
[_plotGrouping:PHPExcel_Chart_DataSeries:private] => stacked
[_plotDirection:PHPExcel_Chart_DataSeries:private] =>
[_plotStyle:PHPExcel_Chart_DataSeries:private] =>
[_plotOrder:PHPExcel_Chart_DataSeries:private] => Array
(
[0] => 0
[1] => 1
[2] => 2
)
[_plotLabel:PHPExcel_Chart_DataSeries:private] => Array
(
[0] => PHPExcel_Chart_DataSeriesValues Object
(
[_dataType:PHPExcel_Chart_DataSeriesValues:private] => String
[_dataSource:PHPExcel_Chart_DataSeriesValues:private] => Worksheet!$B$1
[_formatCode:PHPExcel_Chart_DataSeriesValues:private] =>
[_marker:PHPExcel_Chart_DataSeriesValues:private] =>
[_pointCount:PHPExcel_Chart_DataSeriesValues:private] => 1
[_dataValues:PHPExcel_Chart_DataSeriesValues:private] => Array
(
)
)
[1] => PHPExcel_Chart_DataSeriesValues Object
(
[_dataType:PHPExcel_Chart_DataSeriesValues:private] => String
[_dataSource:PHPExcel_Chart_DataSeriesValues:private] => Worksheet!$C$1
[_formatCode:PHPExcel_Chart_DataSeriesValues:private] =>
[_marker:PHPExcel_Chart_DataSeriesValues:private] =>
[_pointCount:PHPExcel_Chart_DataSeriesValues:private] => 1
[_dataValues:PHPExcel_Chart_DataSeriesValues:private] => Array
(
)
)
[2] => PHPExcel_Chart_DataSeriesValues Object
(
[_dataType:PHPExcel_Chart_DataSeriesValues:private] => String
[_dataSource:PHPExcel_Chart_DataSeriesValues:private] => Worksheet!$D$1
[_formatCode:PHPExcel_Chart_DataSeriesValues:private] =>
[_marker:PHPExcel_Chart_DataSeriesValues:private] =>
[_pointCount:PHPExcel_Chart_DataSeriesValues:private] => 1
[_dataValues:PHPExcel_Chart_DataSeriesValues:private] => Array
(
)
)
)
[_plotCategory:PHPExcel_Chart_DataSeries:private] => Array
(
[0] => PHPExcel_Chart_DataSeriesValues Object
(
[_dataType:PHPExcel_Chart_DataSeriesValues:private] => String
[_dataSource:PHPExcel_Chart_DataSeriesValues:private] => Worksheet!$A$2:$A$6
[_formatCode:PHPExcel_Chart_DataSeriesValues:private] =>
[_marker:PHPExcel_Chart_DataSeriesValues:private] =>
[_pointCount:PHPExcel_Chart_DataSeriesValues:private] => 5
[_dataValues:PHPExcel_Chart_DataSeriesValues:private] => Array
(
)
)
)
[_smoothLine:PHPExcel_Chart_DataSeries:private] =>
[_plotValues:PHPExcel_Chart_DataSeries:private] => Array
(
[0] => PHPExcel_Chart_DataSeriesValues Object
(
[_dataType:PHPExcel_Chart_DataSeriesValues:private] => Number
[_dataSource:PHPExcel_Chart_DataSeriesValues:private] => Worksheet!$B$2:$B$6
[_formatCode:PHPExcel_Chart_DataSeriesValues:private] =>
[_marker:PHPExcel_Chart_DataSeriesValues:private] =>
[_pointCount:PHPExcel_Chart_DataSeriesValues:private] => 5
[_dataValues:PHPExcel_Chart_DataSeriesValues:private] => Array
(
)
)
[1] => PHPExcel_Chart_DataSeriesValues Object
(
[_dataType:PHPExcel_Chart_DataSeriesValues:private] => Number
[_dataSource:PHPExcel_Chart_DataSeriesValues:private] => Worksheet!$C$2:$C$6
[_formatCode:PHPExcel_Chart_DataSeriesValues:private] =>
[_marker:PHPExcel_Chart_DataSeriesValues:private] =>
[_pointCount:PHPExcel_Chart_DataSeriesValues:private] => 5
[_dataValues:PHPExcel_Chart_DataSeriesValues:private] => Array
(
)
)
[2] => PHPExcel_Chart_DataSeriesValues Object
(
[_dataType:PHPExcel_Chart_DataSeriesValues:private] => Number
[_dataSource:PHPExcel_Chart_DataSeriesValues:private] => Worksheet!$D$2:$D$6
[_formatCode:PHPExcel_Chart_DataSeriesValues:private] =>
[_marker:PHPExcel_Chart_DataSeriesValues:private] =>
[_pointCount:PHPExcel_Chart_DataSeriesValues:private] => 5
[_dataValues:PHPExcel_Chart_DataSeriesValues:private] => Array
(
)
)
)
)
)
)
[_plotVisibleOnly:PHPExcel_Chart:private] => 1
[_displayBlanksAs:PHPExcel_Chart:private] => 0
[_topLeftCellRef:PHPExcel_Chart:private] => A13
[_topLeftXOffset:PHPExcel_Chart:private] => 0
[_topLeftYOffset:PHPExcel_Chart:private] => 0
[_bottomRightCellRef:PHPExcel_Chart:private] => H30
[_bottomRightXOffset:PHPExcel_Chart:private] => 10
[_bottomRightYOffset:PHPExcel_Chart:private] => 10
)
AND FromArray has value :
Array
(
[0] => Array
(
[0] =>
[1] => 12/2011
[2] => 01/2012
[3] => 02/2012
)
[1] => Array
(
[0] => QATAR
[1] => 102.77
[2] => 100
[3] => 102.13
)
[2] => Array
(
[0] => SAUDI ARABIA
[1] => 102.74
[2] => 100
[3] => 98.22
)
[3] => Array
(
[0] => KUWAIT
[1] => 94.82
[2] => 100
[3] => 102.28
)
[4] => Array
(
[0] => U.A.E.
[1] => 101.22
[2] => 100
[3] => 99.94
)
[5] => Array
(
[0] => OMAN
[1] => 101.73
[2] => 100
[3] => 100.42
)
)
Please tell me whats going wrong from my side, if nothing then y graph not appearing.

how extract values from multidimensional array

I have this multidimensional array:
Array
(
[car] => Array
(
[responsecode] => 200
[ford] => Array
(
[start] => 0
[count] => 20
[model] => 972000
[results] => Array
(
[0] => Array
(
[date] =>
[clickurl] => xx
[url] => xx
[dispurl] => xx
[title] => xx
[abstract] => xx
)
[1] => Array
(
[date] =>
[clickurl] => xx
[url] => xx
[dispurl] => xx
[title] => Txx
[abstract] => xx
)
I need retrieve value from [model] (972000)
Its really hard for me. Thanks in advance!
if you have your array assigned to a variable say $arry then it would be
$arry['car']['ford']['model']
there are other techniques to get the 'model' from every 'car' in an array, is that what you are looking for?
<?php
$array = array(
"foo" => "bar",
42 => 24,
"multi" => array(
"dimensional" => array(
"array" => "foo"
)
)
);
var_dump($array["foo"]);
var_dump($array[42]);
var_dump($array["multi"]["dimensional"]["array"]);
?>
http://php.net/manual/en/language.types.array.php

cakephp 2.0 hasmany relation retrieve data

I have two model name image and comment. here the relation is like image has many comments . Now in my listing page I want to display all imae detail and only the no of comment on that image . can you tell me how should I get that ?
after I write the query my return data is
Array
(
[0] => Array
(
[Image] => Array
(
[image_id] => 57
[user_id] => 1
[category_id] => 22
[image_title] => scroul
[description] => beutifull natural image for the animal
[keyword] => scrual
[image_price] =>
[image_name] => 7bf4a72509da5906903c84e88228b9dd.jpg
[image_path] => img/uploads/images/original/
[image_available_size] =>
[like] => 12
[size] => 3244
[resolution] => 2162 x 1644
[i_date] => 1348573022
[i_by] => 1
[u_date] => 1348573022
[u_by] => 1
[is_active] => Y
[is_deleted] => N
)
[Comment] => Array
(
[0] => Array
(
[comment_id] => 5
[image_id] => 57
[user_id] => 2
[comment] => socute
[comment_date] => 1348739230
[is_active] => N
[is_deleted] => N
)
)
)
[1] => Array
(
[Image] => Array
(
[image_id] => 56
[user_id] => 1
[category_id] => 22
[image_title] => cute dog
[description] => cute dog looking
[keyword] =>
[image_price] =>
[image_name] => d4af899b0d52cccbec94952a3abd0077.jpg
[image_path] => img/uploads/images/original/
[image_available_size] =>
[like] => 8
[size] => 620
[resolution] => 2592 x 1944
[i_date] => 1348572897
[i_by] => 1
[u_date] => 1348572897
[u_by] => 1
[is_active] => Y
[is_deleted] => N
)
[Comment] => Array
(
[0] => Array
(
[comment_id] => 3
[image_id] => 56
[user_id] => 2
[comment] => ohhhhhhh
[comment_date] => 1348737968
[is_active] => N
[is_deleted] => N
)
)
)
[3] => Array
(
[Image] => Array
(
[image_id] => 55
[user_id] => 1
[category_id] => 22
[image_title] => ships
[description] => ships with beutiful green background
[keyword] => ship,green,animal,nature,background,eating,white ship
[image_price] =>
[image_name] => c0dfc2432ae047e9160f3ef99880fe87.jpg
[image_path] => img/uploads/images/original/
[image_available_size] =>
[like] => 1
[size] => 1831
[resolution] => 2520 x 1944
[i_date] => 1348572846
[i_by] => 1
[u_date] => 1348661976
[u_by] => 1
[is_active] => Y
[is_deleted] => N
)
[Comment] => Array
(
[0] => Array
(
[comment_id] => 2
[image_id] => 55
[user_id] => 2
[comment] => i like it
[comment_date] => 1348737942
[is_active] => Y
[is_deleted] => N
)
[1] => Array
(
[comment_id] => 4
[image_id] => 55
[user_id] => 2
[comment] => good scene
[comment_date] => 1348738004
[is_active] => N
[is_deleted] => N
)
)
)
)
in the above array there is a all comment of that image. I don't want here comment list I just want no of comments .
Could you post the find statement you're using. You can set recursive to a certain level, from the documentation:
-1 Cake fetches Group data only, no joins.
0 Cake fetches Group data and its domain
1 Cake fetches a Group, its domain and its associated Users
2 Cake fetches a Group, its domain, its associated Users, and the Users’ associated Articles
So you can call the following if you only want the data from the current model only:
$this->Model->find('all', array('recursive' => -1));
There is also the Containable behavior, which allows you to specify which Model data you want to retrieve when calling find.
Say you have a Post model which hasMany Image. The call, with the Containable behaviour in the Post Model properly included, would be:
$this->Post->find('all', array(
'conditions' => array('Post.id' => 1),
'contain' => array('Image')
));
EDIT:
Because of the spelling and formatting I misread your initial question. I thought you wanted "no comments" to appear in the data array, instead you want only the "number of comments" to appear.
If you want the comment count, use counterCache as Kishor Kundan proposes.
Cake offers another amazing magic, "counterCache".
You can define the counterCache in your Comments model
public $belongsTo = array(
'className' => 'Image',
'foreignKey' => <your_foreign_key>,
...
...
'counterCache' => true
);
Then you add a field, 'comment_count' in your images table (or the table which is being used by the model Image) and the cake will do the rest for you.
This does add an overhead every time a comment is added/deleted but it is far better alternative than to issue an 'count' every time you fetch image data.
For more info you can check the cookbook. Look out for "counterCache" there.
UPDATE:
To limit the scope for counter cache, use additional attribute 'counterScope' as
public $belongsTo = array(
'className' => 'Image',
'foreignKey' => <your_foreign_key>,
...
...
'counterCache' => true,
'counterScope' => array('Image.active' => 1)
);

Resources