Welcome Guest, Not a member yet? Register   Sign In
DataMapper 1.6.0

[eluser]qureshi[/eluser]
Hi!

I'm using DataMapper, and it's a great tool, but I need some help with it. I've created a thread here:
http://ellislab.com/forums/viewthread/112411/ Perhaps someone familiar with DataMapper could help me. That would be very much appreciated. Thanks.

Nadeem Qureshi

[eluser]bEz[/eluser]
@Qureshi
First off, Welcome to CI!

I would suggest that if you truly want to use DataMapper Library, that you check the USER GUIDE for it.
Then, read-up on the adaption to Datamapper (DMZ edition)

It will unlock the answers on how to take advantage of the Relationships you have from Category to Verses (etc.).
What I'm getting at is that it will depend on whether you want to build the tables to match DataMapper's guidelines or need customization. Wink

[eluser]OverZealous[/eluser]
[quote author="Peet86" date="1240500453"]
Code:
SELECT node.name, (COUNT(parent.name) - 1) AS depth
FROM nested_category AS node,
nested_category AS parent
WHERE ...
I found the count function in Datamapper documentation, but how can I define the "AS" ?
[/quote]

I'm not 100% sure what you are trying to do with your query, here, since you clipped it at the WHERE, so I can't help too much. That being said, you can usually solve a complex query like this in two ways.

1) If possible, just use the normal DM method for selecting. the count() method just counts the number of results in a query, so it may or may not work the way you expect. There's no reason to have an AS, because it just returns a number.

Instead, you might try using the select method, which allows you to write in anything into the SELECT statement. However, the original DM doesn't allow you to return any fields that are not directly on the table (DMZ does) in a get(), so the alternate is to use...

2) The DataMapper query() method. This allows you to pass any query into DataMapper, and return the result. Make sure you read the docs, and make sure you include a unique id for each row.

In general, it is difficult to use DataMapper to query hierarchical relationships, though. You may try looking at using my updated version, DMZ, which supports complex relationships better.

[eluser]OverZealous[/eluser]
@naren_nag

I've tested my application with hundreds of rows, and never had that problem.

Please make sure that you don't have something wrong in your saving code. Is it possible that a save is *failing*, but you aren't checking the result? For example:

Code:
$obj1 = new Object1();
$obj1->value = 'value';
if( ! $obj1->save()) {
    // show error
}

$obj2 = new Object2();
$obj2->get_by_id(1);

$obj1->save($obj2); // <<< Don't assume this will not error!

I've made that kind of mistake before, assuming a save was succeeding when it wasn't.

[eluser]warrennz[/eluser]
@naren_nag

Debug the queries being ran. It may be updating instead of inserting.

And yes, never assume it will save every time.

[eluser]naren_nag[/eluser]
@phil @warrennz

So I checked if the objects were saving and individually they are.

so here's what i'm doing.

$person->get_by_id($id); // This works fine. checked.

$work->designation = $designation etc. // All values reaching controller fine, and being assigned fine.

$work->save($person); // A new record is being created in the workexperiences table, but no corresponding record is being created in the people_workexperiences table. This was working ABSOLUTELY fine till the 199th record was created in the join table.

[eluser]OverZealous[/eluser]
Is it possible you have a $has_many relationship set up as a $has_one? That would cause UPDATEs instead of INSERTs.

[eluser]naren_nag[/eluser]
Double checked all relationships ... this one is a doozy :!

[eluser]OverZealous[/eluser]
Is it possible to reset your data, or set up a temporary database, and try inserting 200 items (via code, of course). Just to see if it is repeatable?

Do you have any related validaters?

Can you manually insert another row into the table?

As warrennz mentioned, turn on CodeIgniter's profiling, and look at the exact queries being run.

[eluser]qureshi[/eluser]
[quote author="bEz" date="1240530212"]@Qureshi
First off, Welcome to CI!

I would suggest that if you truly want to use DataMapper Library, that you check the USER GUIDE for it.
Then, read-up on the adaption to Datamapper (DMZ edition)

It will unlock the answers on how to take advantage of the Relationships you have from Category to Verses (etc.).
What I'm getting at is that it will depend on whether you want to build the tables to match DataMapper's guidelines or need customization. Wink[/quote]

Hi,

I have read the documentation but it doesn't cover such complex relations, and I don't even understand what DMZ documentation says, or what DMZ even does that DM can't. It would be best if you could post your replies to me in the thread that I have created and linked to in my previous post, since I have notifications turned on and I don't wish to receive notifications merely when this thread is updated.

Basically, I'm hoping that I can do something like this to get all my data:
$data = new Category();
$data->get_where('id', $id)->verse->translation->translator;

But that doesn't work. If it did, it would've given me (1) all the verses in a category,(2) the translations for each verse, (3) the translator name of each translation. An array like this:

Verse1
-----Translation1
----------------Translator

-----Translation2
----------------Translator

-----Translation3
----------------Translator

-----Translation4
----------------Translator

Verse2
-----Translation1
----------------Translator

-----Translation2
----------------Translator

-----Translation3
----------------Translator

-----Translation4
----------------Translator


Verse3
-----Translation1
----------------Translator

-----Translation2
----------------Translator

-----Translation3
----------------Translator

-----Translation4
----------------Translator

Thread: http://ellislab.com/forums/viewthread/112411

Thanks in advance,

Nadeem Qureshi




Theme © iAndrew 2016 - Forum software by © MyBB