SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Active Record Question

    I have been been trying to figure out the best way to implement my models in my MVC framework.

    When I'm creating the models its becoming a bit of a task to keep typing out long database queries.

    I was wondering if there is a better way of doing it?

    I have tried using the active record pattern, but keep coming up againest diffen't problems.

    If I use active record I might want to add a "date_added = now()" at the end of the query, but because the data is in quotes it won't work.

    I haven't found a good active record example that covers all bases for generating SQL.

    My Questions:

    1. Should use active record or not?
    2. Is there any other design pattern I should look into that will speed up my development when querying the database?

  2. #2
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    > I haven't found a good active record example that covers all bases for generating SQL.

    You won't either I'm afraid. That is just the thing about SQL as such as it is in regards to the environment you have to work within.

    My only suggestion is that you use your implementation of the Active Record to cover common ground such as CRUD operations, and separate out the rest in so far that you follow the Criteria formula?

    You construct your SQL elsewhere (which isn't too bad an idea, considering), and once ready, pass that into your Active Record if required, to work with that given row of data in question.

    Essentially then, you set up your Active Record with a row of data which does nothing until you've passed in your Criteria object. One thing I don't like about the Active Record is in regards to relationships between data.

    The restrictiveness of the Active Record suggests the only option is to go down the RoR route in how it manages the problem but that again doesn't solve all edge cases as you note.

    Only my thoughts though

  3. #3
    SitePoint Member
    Join Date
    May 2006
    Location
    Russia, Komsomolsk-on-Amur
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by blueyon View Post
    2. Is there any other design pattern I should look into that will speed up my development when querying the database?
    in my works and OS project (see signature) i prefer to use my implementation of The Data Mapper Pattern, which includes the best practicies both from phpDoctrine and propel. I think that DM is more flexible and 'cleaner' than AR


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •