ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

DataMapper 1.6.0

September 05, 2008 12:32pm

Subscribe [115]
  • #1006 / Jan 16, 2011 5:09am

    juanin

    4 posts

    After that the index example works but each link give me 404 error pages.

  • #1007 / Jan 16, 2011 6:03am

    WanWizard

    4475 posts

    Datamapper 1.6.0 is a very old version. The current version is 1.8.0, use the search.

    The included examples are tested on the current release version of CI, which is still 1.7.3. If you want to use 2.0, you’ll have to make the modifications yourself.

  • #1008 / Jan 16, 2011 6:05am

    juanin

    4 posts

    See http://datamapper.exitecms.org/pages/download.html for all official releases, or http://bitbucket.org/wanwizard/datamapper/get/tip.zip for the current development version (which is going to be 1.8.0 in a week or so).

    I downloaded your example but please don’t use <? but <?php…best practice.

  • #1009 / Jan 16, 2011 8:13am

    WanWizard

    4475 posts

    The example is old and not maintained. I haven’t looked at it since I’ve taken over Datamapper from Overzealous. I have to find some time to update it…

  • #1010 / Mar 18, 2011 8:35am

    denis747

    6 posts

    Thanks very much WanWizard and all those working on Datamapper. I like it very much and I am changing my website to use it, I was using active record before. With Datamapper the site is easy to maintain and whenever I want to add any feature that accesses the database it is very easy with Datamapper. Before I discovered Datamapper, i spent about two weeks learning Doctrine2, made it work on the development server on my pc which has php 5.3. To my horror Doctrine2 could not work on the production server as my webhost has a button that says switch to php 5.3 but it doesn’t as the server php configuration is still php 5.2. I like Datamapper as it so flexible like codeigniter. I will continue using Datamapper as the documentation is very good and clear, lots of examples too.

  • #1011 / Aug 03, 2011 6:46pm

    heldrida

    14 posts

    Hi,
    for the following scheme:

    ——————————————————————-
    table -> Campaigns
    id | name | alias | start_date | end_date

    ——————————————————————-
    table -> Campaigns_products
    id | campaign_id | product_id

    ——————————————————————-
    table -> Products
    id | reference | name | description

    ——————————————————————-

    table -> Categories
    id | name | parent_category_id
    ——————————————————————-

    table -> Products_categories
    id | product_id | category_id

    ——————————————————————-

    - A product can have many categories;
    - A product can have many Campaigns;

    My question is, I dont know how to get a product, that can be in many
    categories, in a specific campaign:

    - The product must be in catA or catB or catC or catD;
    - AND it must be of campaignX;

    Here’s some code http://pastie.org/2316484

    I can do this by writting SQL, but I would like to understand how I can accomplish
    this trough Datamapper.

    The lines 59 to 70
    
                    foreach ( $cat As $k => $v )
                    {                
                        if ( $i == 0 )
                        {
                            $prod->where_related($v);
                        }
                        else
                        {
                            $prod->or_where_related($v);
                        }
                    $i++;
                    }
    
    
    The lines 80 to 88
    
                $cpgn = new Campaign();
                $cpgn->where('id', $cpgn_id)->get();
                
                if ( ! $cpgn->exists() )
                {
                    return FALSE;
                }
    
                $prod->where_related($cpgn)->get();

    On $prod->where_related($cpgn)->get(), I’m getting a product that is campainX, that is not part of the selected category.

    Also, is there a way to see the query it generated ? What I do often is to place typos to get the error msgs with the query. From the last querys I saw, I guess I could solve this if I had the “AND_WHERE” or something :T

    the following query works fine:
    
    SELECT * FROM `products`
    INNER JOIN `products_categories`
    ON `products_categories`.`product_id` = `products_categories`.`category_id`
    INNER JOIN `campaigns_products`
    ON `campaigns_products`.`product_id` = `products`.`id`
    INNER JOIN `campaigns`
    ON `campaigns`.`id` = `campaigns_products`.`campaign_id` 
    WHERE (
    `products_categories`.`category_id` = 1 
     OR `products_categories`.`category_id` = 3
    OR `products_categories`.`category_id` = 4
    OR `products_categories`.`category_id` = 5
    )
    AND `campaigns`.`id` = 1

    Thanks a lot for looking!

  • #1012 / Aug 03, 2011 7:55pm

    WanWizard

    4475 posts

    You can dump the SQL by using $yourobject->check_last_query().

    And I suspect you have an issue with where order here, as you correctly stated, the categories need to be within brackets. See http://datamapper.wanwizard.eu/pages/get.html#Query.Grouping on how to do that.

    And my I suggest you upgrade your Datamapper? v1.6.0 is ancient. And if you’re not using this version, you’re posting in the wrong thread.

  • #1013 / Aug 03, 2011 8:00pm

    heldrida

    14 posts

    Thanks a lot for looking and taking tour time, I really appreciate it!
    I dont know if I should copy and paste to the new thread, but I guess I’ll do that.

    I tought I’ve checked all the document, didnt noticed the query.grouping :X I’ll test
    it!

  • #1014 / Aug 24, 2011 8:25am

    duy.1407

    3 posts

    I have a sharing video site.
    Can I do this with DataMapper: get a user, count user’s comment and user’s video at the same time, or i have to modify it myself.
    I do not want to do it with three different statement. i want to combine one.
    need help to start using it.

  • #1015 / Sep 19, 2011 6:40pm

    byteo

    10 posts

    Hi all!
    datamapper is nice..but..

    $anag = new Anagrafica();
            $anag->EMAIL=$this->input->post("email");
            $anag->FOTO=$this->input->post("fotoPath");
            $anag->NOME=$this->input->post("nome");
            $anag->COGNOME=$this->input->post("cognome");
            $anag->RAG_SOCIALE=$this->input->post("codicefiscale");
            $anag->SESSO=$this->input->post("sex");
            $anag->DATA_NASCITA=$this->input->post("datanasc");
            $anag->COMUNE_ID=0;
            if($anag->save())
            {
                $anag->where('EMAIL', $this->input->post("email"))->get();
                    if($user->save($anag))
                                echo "ok!";
                      }

    It’s doesn’t work!! why?
    Thank you!

  • #1016 / Sep 20, 2011 8:27am

    WanWizard

    4475 posts

    Datamapper 1.6.0 is no longer supported. Upgrade the 1.8.1 and use the correct thread to report any issues.

    And if you do that: WHAT doesn’t work? I haven’t got a clue what IT is!

    An assuming $user is a valid user object, you can save and relate in one go:

    $anag->save($user);
  • #1017 / Sep 20, 2011 9:53am

    byteo

    10 posts

    I just use the 1.8 version! 😊

    My problem is:

    I need to save 2 objects: Anagrafica and User.
    User has a FK with Anagrafica… ( ‘anagrafica_id’ field).
    Now,
    I Save my “Anagrafica” Object (and it’s ok..see prev post)
    After I have to Save my “User” Object with “Anagrafica” Foreign Key ...

    $user=new User();
    $user->login="aaaa";
    $user->password="xxxx";
    $user->save($anag);

    but it doesn’t work!

    why?

    THANK YOU!!

  • #1018 / Sep 20, 2011 10:54am

    WanWizard

    4475 posts

    If $anag in your example is a new object, then no, it doesn’t work.

    The reason for that is that to be able to set the anagrafica_id FK, $anag->id must be set. And that is only the case on an existing (saved) object, not on a new object (in that case $anag->id = NULL).

    If both objects are new, use

    $user->save($anag->save());

    This saves $anag first, and uses the return value (the object itself) as relation for $user.

  • #1019 / Sep 20, 2011 11:07am

    byteo

    10 posts

    ok .. but first I saved $anag ..
    I Saved my “Anagrafica” Object:

    if($anag->save())
            $user->save($anag)
  • #1020 / Sep 20, 2011 4:17pm

    WanWizard

    4475 posts

    You are giving conflicting information, the two code snippits (where you create $user and $anag) in the posts above are not identical.

    If this doesn’t work, you have an error elsewhere:

    $user->save();
    $anag->save();
    $user->save($anag);
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases