Yii Framework Forum: CActiveRecordMetaData interface - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CActiveRecordMetaData interface Rate Topic: -----

#1 User is offline   notzippy 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 201
  • Joined: 06-October 08

Posted 16 October 2008 - 03:04 PM

Hi

In my active record implementation the backing table may not exist when the record is created. If the CActiveRecord.getMetaData() returned a IActiveRecordMetaData instance I can swing it by implementing my own. (Currently I can fake it by returning a class which does the same as the CActiveRecordMetaData)

I think this could be useful in some applications. Possible ?

Thanks
NZ
0

#2 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,856
  • Joined: 04-October 08
  • Location:DC, USA

Posted 16 October 2008 - 03:14 PM

Explain a bit more why your scenario would happen in practice?

Since CActiveRecordMetaData is mainly for internal use, exposing it as an interface may not be good as it contains many public properties which can't be declared via interface.
0

#3 User is offline   notzippy 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 201
  • Joined: 06-October 08

Posted 16 October 2008 - 03:35 PM

My goal is pretty simple,

1) A "setup module" function is called.
2) This invokes an instance of my active record and calls the setup() function on it.
3) The setup function calls the getFields() which returns a map of the fields and some meta data about the field types.
4) The setup function then creates the table based on the information returned by getFields().

Right now step 2 fails ..
0

#4 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,856
  • Joined: 04-October 08
  • Location:DC, USA

Posted 16 October 2008 - 03:50 PM

What about adding createMetaData method to CActiveRecord so that you can override to create your own version of metadata object? You can then either extend CActiveRecordMetaData or write one from scratch.
0

#5 User is offline   notzippy 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 201
  • Joined: 06-October 08

Posted 16 October 2008 - 03:59 PM

There is already is a getMetaData method available which is easy enough to override. The issue lies with CActiveRecordMetaData, I cannot override its constructor. If the check for the existence of the table was moved to a protected method like init(), then I could override that call with my own implementation.
0

#6 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,856
  • Joined: 04-October 08
  • Location:DC, USA

Posted 16 October 2008 - 04:10 PM

Why can't you override the constructor? I can't see the difference by moving the code from constructor to init... Maybe you need to access the private member $_model?
0

#7 User is offline   notzippy 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 201
  • Joined: 06-October 08

Posted 16 October 2008 - 06:09 PM

Yes by overriding the constructor it makes overriding all the other methods necessary - so it is almost like an interface :D

Hmm CActiveRecord is a bit different from Prados' active record so there may be an alternative way to approach this for me.

Thanks for the help I will let you know if there is an alternate approach to my issue.

0

#8 User is offline   notzippy 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 201
  • Joined: 06-October 08

Posted 20 October 2008 - 09:01 AM

My final approach was to use two classes, one extendable (my new "BActiveRecord"), the second a final class extending CActiveRecord. In the second class the getMetaData function was overridden to provide my own map of meta data objects. I can then create a new instance of the "BActiveRecord" without having the table in place.

This works well enough although I still think it would be useful to be able to define the table structure without having to goto the database table to fetch the column names for two reasons: 1) Performance - an array can be read from a lot quicker then a table schema, 2) Flexibility - Maybe you do not want to populate or retrieve all the fields from the table or the table does not exist yet.

nz
0

#9 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,856
  • Joined: 04-October 08
  • Location:DC, USA

Posted 20 October 2008 - 09:34 AM

I will keep this in mind. At this moment, let's keep the current design as we may change CActiveRecordMetaData. Wei and I are working on a scheme that would integrate SQLMap and AR, which would essentially solve the point 2. While for point 1, since the DB schema supports caching, so reading the schema data is shouldn't pose too much performance impact.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users