Invalid Attribute name while getting collection : Magento - magento

I am getting the following error -
Fatal error: Uncaught exception 'Mage_Eav_Exception' with message 'Invalid attribute name: subcategory_id.' in /home/dev-cm/public_html/magento2/app/Mage.php:536 Stack trace: #0 /home/dev-cm/public_html/magento2/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php(1155)
Mage::exception('Mage_Eav', 'Invalid attribu...') #1 /home/dev-cm/public_html/magento2/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php(1240)
I have actually added a custom field directly to the table in the database. It was already a custom table too. For making entries too setSubcategoryId() method didn't work. So I saved it through making db connection and saving it through query which is not good idea.
But getSubcategoryId() method worked for getting this field value from collection. Now I am trying to get records for filtering through this field but it's not working and showing the above error. Below is the code that's showing this error -
Mage::getModel('catalog/merchant')->getCollection()->addFieldToFilter('subcategory_id','123');
I searched about it a lot but didn't found any solution. I also flushed magenta cache and re-indexed data but it didn't work. I think I need changes in core files but I don't know what and how to do them.
So I need to get setSubcategoryId() method and the above error fixed for this custom field

i guess you are extending the wrong collection... you are using (extending) an eav collection while you should extend a mysql4 collection.

Related

How to check thrown errors during Sequelize validation execution

I have a sequelize model, which needs custom validation. That custom validation relies on some foreign keys being valid (valid as in valid uuid, not checked that they exist in db) on a record. There is also another validator appended that checks for mutual exclusivity of the foreign keys (only one can be present at the same time). After all this, I access the database in another validator to fetch data from another collection. I dont want this to happen if any of above validators fail because I dont want to access the database if I dont have to and I dont want to check if uuid is valid again because that is a job for one of previous validators.
The order is like so:
check if field contains valid type (uuid) - field type validator
check that field is not clashing with another field (mutually exclusive) - model-wide validator
fetch record from another collection to do further validation - model-wide validator
I want to check if previous validator has already thrown an error and not execute the next one if it has. Even better if I can check which one has thrown an error. Sequelize executes all validators even if error was already thrown. In documentation it says:
Any error messages collected are put in the validation result object
alongside the field validation errors, with keys named after the
failed validation method's key in the validate option object. Even
though there can only be one error message for each model validation
method at any one time, it is presented as a single string error in an
array, to maximize consistency with the field errors.
I tried several ways to access this "error" object but to no avail. Is there a way at all to know if error was already thrown by one of previous validators?

Idempiere UpdateAction webservice is returning error message: cannot set column message

I created a webservice to update a column value in a table. While calling it using SOAP request xml, getting error message like: Cannot set value of column.
For users table, I am able to call similar webservice without any issue. But, this issue is coming with particular table. In which case, this message might come? Cannot set value of column.
Check the log on the server, the cause of that failure is logged in SEVERE level.
This exception if you are using non supported value. If your field is boolean type then use Y or N as value.

how to create view of field collection in drupal 7

when i am creating a view of field collection they give error when we add fields in view
error is that:
An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: /en/admin/structure/views/view/new_page/preview/page/ajax
StatusText: error
ResponseText: Exception: Invalid field name given: field_translations is not a Field Collection field. in FieldCollectionItemEntity->__construct() (line 210 of /home)
how handle this problem
To create field collection view you need to add relationship to the Field collection first and than you can use it. The above error seems like you're using a wrong field.
Check if the field field_translations still exists as a field collection field on your installation (probably not anymore). Apparently removed fields remain inside the database table of Field Collection.
To solve this:
Take a database backup of your current installation (just to make sure)
go to your database, find the table field_collection_item and
explore it
find all the items referencing to field mentionned in the error (in
this case this would be field_translations)
Remove all these items and clear the cache of your Drupal
installation
(Source)

how to customize joomla db sql error messages and how to prevent duplicate entries

my showtime table contains following fields,
id, name, showtime where id is a int type auto-increment field(pK). showtime time type unique field .
when I try to add a showtime(duplicate value) to showtime field($row->store()) it shows the following joomla error message.(I used $row->getError() method)
TableShowTime: :store failed
Duplicate entry '10:30:00' for key 'showtime' SQL=INSERT INTO `jos_myextension_showtime` (`id`,`name`) VALUES ('0','evening')
I want to know is there any way to show only the db error message without showing sql query.
I have an idea to check the duplicate values using a query before insert, is it a good practice? Plz Help.
I think that if you don't want to display the query, then you shouldn't show the other part of the error message neither (don't tell the user you're trying to insert a duplicate key). A simple fix to this might be something like this:
if ( $row>getError() ) {
echo "Could not store [...]";
}
If this is a custom component, you could also modify your table class to customize these error message, or even show distinct error messages depending on the error number.
I hope it helped!

SOlving the problem of unique key in joomla

I am novice to joomla. I am using Joomla 1.5. I have declared a field in database table as unique. Lets suppose , I have declared "username" as unique . I created a component named "com_user" in the administrator/components section. Now, when I add a user "xyz123", for the first time, its ok. But, during next entry, when I enter the same value, it should generate error with displaying error message showing "Username should be unique" or sth. like this . How can this be done?
The best way to do this I think is to just do a "select count(*) from..." before you try to insert the user into the database to see if the user already exists. The best way to display errors, warnings and notices would be to use the JError class
A second way is to use the getErrorNum() and getErrorMsg() methods of the DBO object.
More information on that here: http://www.joomladin.com/index.php/tutorials/34-module-development/54-exception-handling.html Although I do believe that while using this second method the user still might see a big red "Database Error: duplicate key..." message.
The store() method of your JTable class should return false when the query fails, so you could use this to determine when a duplicate record is being entered. However, the store() method will also return false when the query fails for other reasons (lost database connection, etc...).

Resources