Model with EAV capabilities

Hi All,

I’m working on a project that has to get some data(from the customer tables)(read only) from a magento database.

The table is set up in an EAV format which makes getting the data a little tricky.

Here’s an example table:

value_id entity_type_id attribute_id entity_id value

1 12 212 1 billing

2 12 217 1 oliver

3 12 219 1 haueee

4 12 221 1

5 12 222 1 155 herman ville

6 12 223 1 Overton

7 12 224 1 Nevada

8 12 226 1 89040

9 12 227 1 US

10 12 228 1 111-111-1111

entity_id is the customer id and each ‘attribute_id’ is an attribute of the address e.g. 217 is first name, 219 is last name.etc

I’ve been trying for a couple days now to create a model to access this data and use it in related model but i’m going nowhere.

I’ve tried to implement the YiiEtx in eav-behavior but no success either.

Any suggestions as to how i could access this data?

I can write a raw MySQL query to get the data in a snap but trying to figure it out in yii is having me scratch my head.

Is there a way i can create a model based on a raw SQL query?

Thanks in advance.


For EAV data, I’d create a view in the database to transpose the EAV structure into a flattened record. You can then create the model based on the database view. For any volume of data, performance is going to suck, but that’s the tradeoff of EAV.

@bglee Thanks for the response…I’ve never used MySql views before…but they look to be exactly what i’m looking for.