SitePoint Sponsor

User Tag List

Page 4 of 5 FirstFirst 12345 LastLast
Results 76 to 100 of 105
  1. #76
    SitePoint Guru thr's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    664
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lastcraft
    1) As you've pointed out, code generate the SQL and also the classes on demand. This is tricky and you may end up with a build step just to ease the pain. In most commercial environments though, this extra work is no problem and you get actual generated files to look at when youare not sure what's happening. That's the way most persistence layers do it.
    This is the version I'm starting to lean agains, yes it's the way propel does and I do have a thing or two against it, but it's the lesser of multiple evils .

    Quote Originally Posted by lastcraft
    2) The problem you presented is not a show stopper. You have a "from" attribute and a "to" attribute and they both give back a person. Assuming you can introspect the foreign keys (with MySQL 5 you can do most of SQL2003), I don't see the issue. The Identity maps covers you against "from" and "to" being the same person. What am I missing ?
    Well, the problem is that for Referencial Integrity to work you have to support MYSQL5 i think ? The problem i posed was that if you have a field named "to" there is no way in the world that you'r orm-layer is going to be able to tell that a person object should be there? (without configuration that is). And doesn't it require InnoDB as Tabletype/engine?

    Quote Originally Posted by lastcraft
    3) Mixing XML and SQL is just yucky unles you embed the SQL in the XML. It's still yucky.
    Agreed.

    Quote Originally Posted by lastcraft
    4) Use the doclet/annotations system in the way hibernate does...
    PHP Code:
    class SaveMe {

        
    /**@ persistent varchar(255) username primary key */
        
    function getUsername() { ... }

    The Reflection system reads these in PHP 5.1+.
    I realy don't like this approach, way to icky and prone to errors imho.

    Quote Originally Posted by lastcraft
    5) Use the variable names...
    PHP Code:
    class PersonAccessor extends DataAccessor {
        private 
    $username_varchar_primarykey;

    A bit freaky, but it could work. Every string is a potential programming language .
    That hurt my eyes ;p

    Quote Originally Posted by lastcraft
    6) Have a separate schema object...
    PHP Code:
    $schema = new Schema('PersonAccessor');

    class 
    PersonAccessor {
        ...
        static function 
    getMapping() {
            
    $mapping = new Mapping('people');
            
    $mapping->primaryKey('username')->varChar(255);
            
    $mapping->name->varChar(255)->notNull;
            
    $mapping->is_registered->boolean->default(true);
            return 
    $mapping;
        }

    This is quote a nice idea, but well.. I'd prefer the XML-way over this tbh.

    Thanks for all of your ideas, I realy want to do it without configuration - but I don't know if it's possible?

  2. #77
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I suppose if you could dictate the schema

    to_person_id and
    from_person_id

    could automatically generate

    PHP Code:
    $mail->to /* a person object */
    $mail->from /* another person object */ 
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  3. #78
    SitePoint Zealot DerelictMan's Avatar
    Join Date
    Oct 2005
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by thr
    Well, the problem is that for Referencial Integrity to work you have to support MYSQL5 i think ? [...] And doesn't it require InnoDB as Tabletype/engine?
    Sorry if I missed this somewhere previously in this thread, but why are you tied down to MySQL only? Just curious...

  4. #79
    SitePoint Guru thr's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    664
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DerelictMan
    Sorry if I missed this somewhere previously in this thread, but why are you tied down to MySQL only? Just curious...
    I'm not - but considering how much trouble it is getting this to work with just one(mysql) rdbms - I'm sticking to make it work 100% on one rdmbs, and then start workingon the others ;p.

  5. #80
    SitePoint Guru thr's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    664
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sweatje
    I suppose if you could dictate the schema

    to_person_id and
    from_person_id

    could automatically generate

    PHP Code:
    $mail->to /* a person object */
    $mail->from /* another person object */ 
    While this would work, it'd make the SQL-tables kinda messy. I'm sticking with XML for now.

  6. #81
    SitePoint Wizard Ren's Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    1,060
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    InnoDB is required for DRI, MySQL5 for information_schema tables, figuring out relationships on MySQL4 & InnoDB iirc requires an SQL parser. (SHOW CREATE TABLE blah;) and parse the output.

  7. #82
    SitePoint Guru thr's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    664
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Ren
    InnoDB is required for DRI, MySQL5 for information_schema tables, figuring out relationships on MySQL4 & InnoDB iirc requires an SQL parser. (SHOW CREATE TABLE blah and parse the output.
    Ah yes, I thought so. As I said I'm sticking with an XML definition a'la Propel atm. I think I got a way to work around the whole "build"-process and make it "dynamic".

    Now it's bedtime here, cheers .

  8. #83
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi...

    Quote Originally Posted by kyberfabrikken
    Arg.


    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  9. #84
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi...

    Quote Originally Posted by thr
    Well, the problem is that for Referencial Integrity to work you have to support MYSQL5 i think ? The problem i posed was that if you have a field named "to" there is no way in the world that you'r orm-layer is going to be able to tell that a person object should be there? (without configuration that is). And doesn't it require InnoDB as Tabletype/engine?
    OK, I'd forgotten about older MySQL limitations.

    If your target market is one step above ActiveRecord, a tidy little niche, then specifying MySQL5 won't be a problem. UnitOfWork already gives you proper transactions, so to be effective you are looking at the InnoDB format. The kind of user that needs your library will already be doing this.

    I think Jason's idea of coding the foreign key table in the key name is a good workaround for that segment that is using MySQL and using version 4 and not using InnoDB. You could anyway develop on Postgres or MySQL5 while you get everything up and running, and add MySQL4 support later. Postgres and MySQL 5 really are rather nice.

    If you can avoid the XML code generation step, I think you should.

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  10. #85
    SitePoint Addict pachanga's Avatar
    Join Date
    Mar 2004
    Location
    Russia, Penza
    Posts
    265
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by thr
    Quote Originally Posted by lastcraft
    $schema = new Schema('PersonAccessor');

    class PersonAccessor {
    ...
    static function getMapping() {
    $mapping = new Mapping('people');
    $mapping->primaryKey('username')->varChar(255);
    $mapping->name->varChar(255)->notNull;
    $mapping->is_registered->boolean->default(true);
    return $mapping;
    }
    }
    This is quote a nice idea, but well.. I'd prefer the XML-way over this tbh.
    Before going the XML way i think it really makes sense to try the approach suggested by Marcus. After all any sort of XML mapping schema will be internally converted to PHP schema objects.

    Instead of designing XML mapping schema in the first place you can have all your mappings described with PHP objects only. Once you have this working(and of course unit tested) prototype it will be relatively easy to add some XML2YourSchema adapater. Actually you can try any other format, why XML?

  11. #86
    SitePoint Guru thr's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    664
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lastcraft
    OK, I'd forgotten about older MySQL limitations.

    If your target market is one step above ActiveRecord, a tidy little niche, then specifying MySQL5 won't be a problem. UnitOfWork already gives you proper transactions, so to be effective you are looking at the InnoDB format. The kind of user that needs your library will already be doing this.
    Hmm, ok - that's a good point that moste people(including myself) that will be using this(if any are and if i ever finish it ;P) will be using InnoDB from the start.

    Quote Originally Posted by lastcraft
    I think Jason's idea of coding the foreign key table in the key name is a good workaround for that segment that is using MySQL and using version 4 and not using InnoDB. You could anyway develop on Postgres or MySQL5 while you get everything up and running, and add MySQL4 support later. Postgres and MySQL 5 really are rather nice.
    About this, if I put in the ability to code the FK in the fieldname, would you have the application remove the FK-name efter it's been detected or keep it? Or clean it up for the object and not the sql? or leave the name as it is?

    Quote Originally Posted by lastcraft
    If you can avoid the XML code generation step, I think you should.
    Yes I realy wanted to avoid code generation and I've gone to great lengths to not have it in my app - I thought I "lost" the battle yesterday but you'r ideas are nice - going to try them out today/tomorrow - cheers.

    Quote Originally Posted by pachanga
    Before going the XML way i think it really makes sense to try the approach suggested by Marcus. After all any sort of XML mapping schema will be internally converted to PHP schema objects.

    Instead of designing XML mapping schema in the first place you can have all your mappings described with PHP objects only. Once you have this working(and of course unit tested) prototype it will be relatively easy to add some XML2YourSchema adapater. Actually you can try any other format, why XML?
    True. Why XML? Well.. it's commonly know and pretty much standard for these types of things - but if I can get away without it, I will

  12. #87
    SitePoint Addict pachanga's Avatar
    Join Date
    Mar 2004
    Location
    Russia, Penza
    Posts
    265
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Off Topic:


    Quote Originally Posted by thr
    Why XML? Well.. it's commonly know and pretty much standard for these types of things - but if I can get away without it, I will
    I really like Ruby in this regard: it's possible to write very flexible and expressive schemas using calls to Ruby objects directly without any unneccessary additional markup language.


  13. #88
    SitePoint Wizard Ren's Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    1,060
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Back to the discovering relationships, I believe MySQL4 "SHOW CREATE TABLE blah;" on non-InnoDB table types will also show the references, and foriegn keys. Just the DRI isn't enforced.

    Anyone have MySQL4 handy to check, save me re-installing it?

  14. #89
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    The Netherlands
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Ren
    Back to the discovering relationships, I believe MySQL4 "SHOW CREATE TABLE blah;" on non-InnoDB table types will also show the references, and foriegn keys. Just the DRI isn't enforced.

    Anyone have MySQL4 handy to check, save me re-installing it?
    Quote Originally Posted by http://dev.mysql.com/doc/refman/5.0/en/ansi-diff-foreign-keys.html
    For storage engines other than InnoDB, MySQL Server parses the FOREIGN KEY syntax in CREATE TABLE statements, but does not use or store it. In the future, the implementation will be extended to store this information in the table specification file so that it may be retrieved by mysqldump and ODBC. At a later stage, foreign key constraints will be implemented for MyISAM tables as well.
    On MySQL 4.0.18/MyISAM, using these
    Code:
          CREATE TABLE parent (
          	id int not null,
          	PRIMARY KEY (id)
          );
          
          CREATE TABLE child (
          	id int,
          	parent_id int,
          	INDEX par_ind (parent_id),
          	FOREIGN KEY (parent_id) REFERENCES parent(id)
          );
    SHOW CREATE TABLE returns:
    Code:
          CREATE TABLE parent (
               id int(11) NOT NULL default '0',
               PRIMARY KEY (id)
           );
           
           CREATE TABLE child (
               id int(11) default NULL,
               parent_id int(11) default NULL,
               KEY par_ind (parent_id)
           );

  15. #90
    SitePoint Wizard Ren's Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    1,060
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, pah. Thought it might have kept the definition, as it obviously can parse them ok.

    Cheers tho.

  16. #91
    SitePoint Guru thr's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    664
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One more MySQL5 Question: How do I resolve the constraint on a field? (for exaample Message.from and Message.to are contrained FKs to Person.id)

    Do I have to parse the SQL or is there some smarter way in MySQL?(Haven't worked that much with 5.x-series)

  17. #92
    SitePoint Wizard Ren's Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    1,060
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by thr
    One more MySQL5 Question: How do I resolve the constraint on a field? (for exaample Message.from and Message.to are contrained FKs to Person.id)

    Do I have to parse the SQL or is there some smarter way in MySQL?(Haven't worked that much with 5.x-series)
    information_schema.KEY_COLUMN_USAGE (
    http://dev.mysql.com/doc/refman/5.0/...age-table.html ) will show how the columns pair up in a relationship.

    I pasted the SQL in a previous posting on this thread.

    Also almost completed the grammar/parser for CREATE TABLE syntax based on the yacc mysql spec.

    Atm
    Given
    Code:
    CREATE TABLE parent (
          	id int unsigned auto_increment not null,
          	name varchar(30) not null,
          	PRIMARY KEY (id)
          );
       
      CREATE TABLE child (
    	id int unsigned auto_increment ,
    	parent_id int,
    	INDEX par_ind (parent_id),
    	FOREIGN KEY (parent_id) REFERENCES parent(id)
      );
    it dumps out

    PHP Code:
    array (
      
    =>
      array (
        
    'NAME' => 'parent',
        
    'COLUMNS' =>
        array (
          
    =>
          array (
            
    'NAME' => 'id',
            
    'TYPE' => 'int',
            
    'UNSIGNED' => true,
            
    'AUTO_INCREMENT' => true,
            
    'IS_NULLABLE' => false,
          ),
          
    =>
          array (
            
    'NAME' => 'name',
            
    'TYPE' => 'VARCHAR',
            
    'LENGTH' => '30',
            
    'IS_NULLABLE' => false,
          ),
        ),
        
    'PRIMARY KEY' =>
        array (
          
    =>
          array (
            
    'COLUMNS' =>
            array (
              
    => 'id',
            ),
          ),
        ),
      ),
      
    =>
      array (
        
    'NAME' => 'child',
        
    'COLUMNS' =>
        array (
          
    =>
          array (
            
    'NAME' => 'id',
            
    'TYPE' => 'int',
            
    'UNSIGNED' => true,
            
    'AUTO_INCREMENT' => true,
            
    'IS_NULLABLE' => false,
          ),
          
    =>
          array (
            
    'NAME' => 'parent_id',
            
    'TYPE' => 'int',
          ),
        ),
        
    'INDEX' =>
        array (
          
    =>
          array (
            
    'COLUMNS' =>
            array (
              
    => 'parent_id',
            ),
          ),
        ),
        
    'REFERENCES' =>
        array (
          
    =>
          array (
            
    'TABLE' => 'parent',
            
    'COLUMNS' =>
            array (
              
    'parent_id' => 'id',
            ),
          ),
        ),
      ),

    Just needs more testing, and handle some of the alternate methods
    for defining primary keys and references inline with the column definition
    eg.
    id INT PRIMARY KEY
    and
    parent_id INT REFERENCES parent (id)

  18. #93
    SitePoint Guru thr's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    664
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, so I got the part with MySQL 5 + InnoDB + information_schema > Classes working, 1:1, 1:*, etc. all working.

    My last problem now is of a simple nature, yet annoying: Value Objects. Take this table:

    Code:
    create table Person(
    id int not null auto_increment,
    name varchar(50),
    savings int not null default '0',
    primary key(id)
    ) type = innodb;
    The "savings"-field holds the persons savings as an int. Now the problem here is that i want the Savings field to auto-resolve it self into a Money object. This isn't possible without using some type of schema for defining the classes? As there is nothing in the table itself that says "hey, savings is a money object".

    And no, using something like "savings_obj_Money" or "savings_Money" isn't going to do it realy as it's way to "hacky" and ugly =/.

  19. #94
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    not to mention that a Money object would span two columns in the table (value + currency).

  20. #95
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    override as a class property at runtime?
    PHP Code:
    Person::ValueObjectMap(array('savings' => 'Money')); 
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  21. #96
    SitePoint Guru thr's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    664
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sweatje
    override as a class property at runtime?
    PHP Code:
    Person::ValueObjectMap(array('savings' => 'Money')); 
    It feels kinda ugly to put that into every command/action using the Person object?

  22. #97
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perhaps you could address kyberfabrikken issue at the same time by having the specific model class have custom properties:

    PHP Code:
    class Person extends OrmClass {
      function 
    __construct($id=null) {
        if (
    $id) {
          
    $this->loadFromId($id);
        }
        
    $this->hiddenFields(array('currency'));
      }
      function 
    loadFromId($id) {
        
    $this->fields $this->conn->fetchRow(self::SELECT_BY_ID$id);
        
    $savings $this->fields['savings'];
        
    $this->fields['savings'] = new Money($savings$this->fields['currency']);
      }

    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  23. #98
    SitePoint Wizard Ren's Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    1,060
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, be nice if MySql supported custom types.

    Other places could store extra information is an column comment, accessable from
    TABLE_COLUMNS.COLUMN_COMMENT. But its MySql specific extension, and probably the last place anyone expects.

  24. #99
    SitePoint Guru thr's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    664
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The only thing I have against the whole "doing it from SQL" is the fact that it's Objects we're mapping onto SQL and not the other way around. I'm realy considering an XML-approach just to get all the features I wan't without tying me to a specific DB.

  25. #100
    SitePoint Addict
    Join Date
    May 2003
    Location
    The Netherlands
    Posts
    391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is this wrong?

    Code:
    #Money
     - id(pk)
     - amount
     - currency (fk > Currency.id)
    
    #Currency
     - id(pk)
     - name
     - symbol
     - exchange_rate
    
    #Person
     - id(pk)
     - name
     - money (fk > Money.id)
    There’s more than one way to skin a cat.


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
  •